Consulting

Results 1 to 4 of 4

Thread: Correct workbook name

  1. #1
    VBAX Regular
    Joined
    Jan 2009
    Posts
    57
    Location

    Correct workbook name

    I'm trying to get this snippet of code to work (which updates a cell in the first workbook from the second workbook using the variable thisWbName instead of the actual name of of the workbook) but I don't know the correct way to get Excel to understand the variable thisWbName instead of the word.

    Workbooks("~Dog Training Reports & Handler Information").Sheets("Dog and Handler Data").Range(cell).Offset(0, 5).Formula = "='[(thisWbName)]Overview'!$E$28"

    Any ideas please.

  2. #2
    MS Excel MVP VBAX Mentor Andy Pope's Avatar
    Joined
    May 2004
    Location
    Essex, England
    Posts
    344
    Location
    Current the variable is being treated as text because it is contained within the quotes. You need to break the syntax so it can recognise the variable.

    Workbooks("~Dog Training Reports & Handler Information").Sheets("Dog and Handler Data").Range(cell).Offset(0, 5).Formula = _
                       "='[" & thisWbName &"]Overview'!$E$28"
    Cheers
    Andy

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    try
    [vba]~~.Formula= "='[" & thisWbName & "]Sheet1'!$E$17"[/vba] if thisWbName is a string.
    p45cal

    ha.. beaten to it!
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  4. #4
    VBAX Regular
    Joined
    Jan 2009
    Posts
    57
    Location
    Thanks very much, both of you. Works a treat.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •