+ Reply to Thread
Results 1 to 6 of 6

Problem activating workbooks and worksheet with variable name

  1. #1
    Registered User
    Join Date
    03-02-2013
    Location
    London, ON
    MS-Off Ver
    Excel 2016
    Posts
    9

    Problem activating workbooks and worksheet with variable name

    Hi

    I have 2 open workbooks. I am running a macro from workbook 1 which requires activating the second workbook, selecting data from a worksheet in the second workbook and copying into the first workbook. The second workbook name can vary but always begins with "Ad Views"

    I am currently using this code but cannot get it to activate the second workbook to select the data

    Please Login or Register  to view this content.
    Last edited by arlu1201; 03-03-2013 at 02:35 PM.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Problem activating workbooks and worksheet with variable name

    You don't need to activate either workbook.

    Also, this will never find the other workbook as 'Ad Views' is not in lower case
    Please Login or Register  to view this content.
    It's not 100% clear what you are trying to do, mainly because the copy/paste code is inside the loop.

    Anyway, try this.
    Please Login or Register  to view this content.
    PS When posting code can you add code tags - makes it easier to read/understand.
    If posting code please use code tags, see here.

  3. #3
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Problem activating workbooks and worksheet with variable name

    Perhaps you could use the fact that that Excel keeps track of the workbooks it opends and in the order they are opened. So the first workbook you open is Workbook(1) and to activate the second workbook you opens just add the line
    Please Login or Register  to view this content.
    to your code.

    Alf
    Last edited by Alf; 03-03-2013 at 12:14 PM.

  4. #4
    Registered User
    Join Date
    03-02-2013
    Location
    London, ON
    MS-Off Ver
    Excel 2016
    Posts
    9

    Re: Problem activating workbooks and worksheet with variable name

    Hi Thanks

    I am afrraid that did not work

    The name of the workbook is actually "Ad Views" follwed by a variable and does have upper case initial letters in the words.


    To clarify, I am using the vba macro in a first workbook to copy a dynamic range from a second workbook and paste into the first workbook. The problem is that the second workbook name could be Ad Views (1) , Ad Views (2) etc. There is only one worksheet in the second workbook.

    Thanks

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Problem activating workbooks and worksheet with variable name

    In what way does it not work?

    Why are you converting the workbook name to lower case with LCase and then comparing it to a string with upper case letters?

    Also, normally when using Like you would include a wildcard.

    For example, this will find a workbook with 'Ad Views' at the start of the name.
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Problem activating workbooks and worksheet with variable name

    Jemwig,

    Welcome to the forum.

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. If you need more information on how to use them, check my signature below this post.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1