+ Reply to Thread
Results 1 to 9 of 9

Defining and setting workbook object variable?

  1. #1
    Registered User
    Join Date
    10-01-2008
    Location
    Park City
    Posts
    59

    Defining and setting workbook object variable?

    I'm working on my first macro that works over multiple workbooks and I'm stuck at line 1. I obviously have the syntax wrong but I can't figure out why this code doesn't work. Do I need the full pathname for the workbook name?

    Please Login or Register  to view this content.
    I know... I know, this should be basics 101!

    GG

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Defining and setting workbook object variable?

    If you have a Training2.xlsx active then your code should run - are you getting a subscript error?
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Defining and setting workbook object variable?

    Nothing wrong with the syntax. You might not have a workbook called Training2.xlsx in the workbook you are working.

    Please Login or Register  to view this content.
    Last edited by AB33; 06-16-2014 at 02:41 PM.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: Defining and setting workbook object variable?

    Hi, AB33,

    You might not have a sheet called Training2.xlsx in the workbook you are working.
    Not so sure that I can understand what you refer to but I have only limited knowledge of VBA, could you please explain?

    Please Login or Register  to view this content.
    should raise a RTE as wb is dimmed as workbook?

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Defining and setting workbook object variable?

    I would have, but since you are a person with full of sarcasm, I have not desire nor the intention to communicate with you. I have made this clear on many occasions( In case you missed one of them)

    "I have only limited knowledge of VBA"

  6. #6
    Registered User
    Join Date
    10-01-2008
    Location
    Park City
    Posts
    59

    Re: Defining and setting workbook object variable?

    Quote Originally Posted by xladept View Post
    If you have a Training2.xlsx active then your code should run - are you getting a subscript error?
    Ah ha! I didn't have Training2.xlsx open. Doh! I looked at this code for about an hour trying different syntax and the answer was simple.

    Please Login or Register  to view this content.
    I'll have to make sure I error proof the code in the event I get this error in 6 months and I forget the reason

    I suppose there is no way to work on a closed workbook, it has to be open right?

    GG

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Defining and setting workbook object variable?


  8. #8
    Registered User
    Join Date
    10-01-2008
    Location
    Park City
    Posts
    59

    Re: Defining and setting workbook object variable?

    Thank you for the help and the link.

    GG

  9. #9
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,199

    Re: Defining and setting workbook object variable?

    Hi, AB33,

    maybe have another look at the code from TO and your sample - having a variable dimmed as workbook and trying to assign a worksheet does it make necessary to communicate I´m afraid as Run-Time Error 13 should be raised when trying to run the code line.

    Ciao,
    Holger

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Defining workbook variable not working with workbooks.open
    By hmbugg in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-07-2013, 02:09 PM
  2. [SOLVED] Setting an Object to a Variable
    By djbomaha in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-27-2012, 04:53 PM
  3. setting a workbook object using a workbook name that is a variable
    By amazingg64 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-07-2012, 08:23 PM
  4. setting object variable
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-13-2005, 03:06 PM
  5. Problems Defining Object Variable in For Each Loop
    By ExcelMonkey in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-28-2005, 07:06 PM

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