+ Reply to Thread
Results 1 to 4 of 4

setting a workbook object using a workbook name that is a variable

  1. #1
    Registered User
    Join Date
    06-04-2012
    Location
    Waterloo, iA
    MS-Off Ver
    Excel 2007
    Posts
    14

    setting a workbook object using a workbook name that is a variable

    I don't understand what I'm doing wrong. I want to assign the variable wkbWIW so I can use it in place of Workbooks("7000GT.xlsm) Here's what I have:

    Please Login or Register  to view this content.
    The code finds the workbook 7000GT.xlms but when I try to set the variable wkbWIW, it doesn't do anything (and causes an error in the rest of the code). The code runs over and over with a lot of different sWIWName values so I have to keep it a variable. Keep in mind the code is an excerpt and I'm just worried about the task of assigning the Workbook object.

    Thanks ahead of time!!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: setting a workbook object using a workbook name that is a variable

    As long as a workbook called 7000GT.xlsm is already open in the same instance of Excel, that should work.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    06-04-2012
    Location
    Waterloo, iA
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: setting a workbook object using a workbook name that is a variable

    So after executing that statement, I should be able to hover my mouse over it and it will say "Workbooks("7000GT.xlsm)," right?

    The next statement sets a Worksheet object as wkbWIW.Sheets("Input")

    Please Login or Register  to view this content.
    and when I step into it, it throws an error. Could that be my problem? (Assuming the sheet object is defined)

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: setting a workbook object using a workbook name that is a variable

    Make sure there is no ON ERROR RESUME NEXT in effect. You want the code to ERROR where it needs to when debugging.

    If it errors on that line of code, DEBUG.
    In the Immediate Window (Ctrl-G), put this:

    ? wkbWIW.Name

    Then:

    ? wbkWIW.Sheets("Input").Index

    Anything useful in response? This sounds like you're addressing objects that don't exist. Object names are exacting, watch for hidden spaces.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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