+ Reply to Thread
Results 1 to 15 of 15

VBA Run-time error ‘91’: Object variable or With block variable not set

  1. #1
    Registered User
    Join Date
    10-24-2014
    Location
    Vancouver, BC
    MS-Off Ver
    2013
    Posts
    7

    VBA Run-time error ‘91’: Object variable or With block variable not set

    Hi All,

    I'm new to VBA though consider myself pretty handy with Excel. I've had this program that we use at work dropped in my lap because it's throwing multiple errors and I'm overwhelmed.

    I've gone through a number of VBA tutorials and used this excellent forum and a few others to solve most of the problems.

    I'm now stuck on this one run-time error '91' that pops up with I start the program. I've spent so much time trying to figure it out I'm ready to pull out my hair.

    I won't speculate on the problem, hopefully someone more knowledgeable than me can give me some help.

    The highlighted area in debugger is:

    Please Login or Register  to view this content.

    Thanks so much for for any and all help!


    Here is the whole selection:

    Please Login or Register  to view this content.
    Last edited by The Enthusiast; 10-24-2014 at 12:30 PM.

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: VBA Run-time error ‘91’: Object variable or With block variable not set

    Where is wbkTT declared/assigned a value...?

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

    Re: VBA Run-time error ‘91’: Object variable or With block variable not set

    What happens if you change ActiveWorkbook to ThisWorkbook?
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    10-24-2014
    Location
    Vancouver, BC
    MS-Off Ver
    2013
    Posts
    7

    Re: VBA Run-time error ‘91’: Object variable or With block variable not set

    Hi cytop, thanks for the response.

    I see:

    Please Login or Register  to view this content.
    then
    Please Login or Register  to view this content.
    and finally the error
    Please Login or Register  to view this content.

    I also added:

    Please Login or Register  to view this content.
    But no joy...

    Thanks again!
    Last edited by The Enthusiast; 10-24-2014 at 12:31 PM.

  5. #5
    Registered User
    Join Date
    10-24-2014
    Location
    Vancouver, BC
    MS-Off Ver
    2013
    Posts
    7

    Re: VBA Run-time error ‘91’: Object variable or With block variable not set

    Hi Norie,

    If I change it to ThisWorkbook to causes the same error a few lines of code down at the next ActiveWorkbook. If I then change that to "ThisWorkbook" it causes a run-time error 9 - "subscript out of range".

  6. #6
    Forum Contributor
    Join Date
    06-21-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    191

    Re: VBA Run-time error ‘91’: Object variable or With block variable not set

    Try removing the file extension from the name when you set the Const (drop the .xlsm)

  7. #7
    Registered User
    Join Date
    10-24-2014
    Location
    Vancouver, BC
    MS-Off Ver
    2013
    Posts
    7

    Re: VBA Run-time error ‘91’: Object variable or With block variable not set

    Hi soberguy, thanks for the response! I just tried it and get the same error

    This may just be my ignorance of VBA but I'm wondering if the new workbook generated by...

    Please Login or Register  to view this content.
    ...needs to be referenced/named newTTwbk. Does Excel automatically relate the freshly opened workbook at newTTwbk?

    I so far have

    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    Based on those 3 lines, if Excel doesn't automatically relate the new workbook to newTTwbk then all references to newTTwbk are superfluous, no?

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

    Re: VBA Run-time error ‘91’: Object variable or With block variable not set

    What new workbook is being generated?

  9. #9
    Forum Contributor
    Join Date
    06-21-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    191

    Re: VBA Run-time error ‘91’: Object variable or With block variable not set

    I don't see the point of having one string equal another string. Why not use the same variable? In other words, what's the point of:
    Please Login or Register  to view this content.
    As to the issue at hand, I'm not really sure what the issue is. With an ActiveWorkbook, the name is returned without the file extension (hence my previous post).

    Upon testing the Workbook_Open event, it does expect the file extension to be included with the name.


    Walk me through how you're calling this. Does this code just run when you open this particular workbook? Are you opening this workbook from code in another workbook?

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

    Re: VBA Run-time error ‘91’: Object variable or With block variable not set

    The Enthusiast

    Which workbook is ActiveWorkbook supposed to refer to?

    Is it the workbook this code is in, or another workbook that's open at the same time?

    Where is the code located anyway?


    soberguy

    I think in VBA the file extension is always returned with the Name property.

    Mind you I don't think that's the problem.

  11. #11
    Forum Contributor
    Join Date
    06-21-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    191

    Re: VBA Run-time error ‘91’: Object variable or With block variable not set

    Interesting. I can return it with and without the file extension. I'll have to play with that.

  12. #12
    Registered User
    Join Date
    10-24-2014
    Location
    Vancouver, BC
    MS-Off Ver
    2013
    Posts
    7

    Re: VBA Run-time error ‘91’: Object variable or With block variable not set

    Thanks for the help guys, here's the story...

    I didn't build or write this program, the person who did is long gone, and I'm trying to wade through it and make it function without errors again.

    When I open the Excel file the code listed in my original post runs automatically and is supposed to activate the macros in the RibbonXAddin to add functionality to the program. However, it's getting hung up with the " Run-time error ‘91’: Object variable or With block variable not set ". The Debugger box opens up and if I select "END" the spreadsheet opens but the macros are not activated. If I choose to "DEBUG" the debugger console opens up and highlights the line of code referenced above.

    From this point I can select "RUN" and "CONTINUE" or punch F8 through the rest of the code and it steps over the ERROR 91 and walks through the rest of the code without problem and activates the program. I can then use the program as built without problems.

    So the real problem is getting hung up when I start the program and that's what I'm mandated to fix because the majority of people who will be using the program will destroy it if they are allowed free access to the debugger console.



    I am not sure where or how the newTTwbk = wbkTT line comes into effect and yes it seems like a circular reference.

  13. #13
    Registered User
    Join Date
    10-24-2014
    Location
    Vancouver, BC
    MS-Off Ver
    2013
    Posts
    7

    Re: VBA Run-time error ‘91’: Object variable or With block variable not set

    Norie, the program consists of the 2 files listed in the top of the code.

    Please Login or Register  to view this content.
    ActiveWorkbook is the .xlsm, opening the .xlsm file automatically runs the .xlam file which contains all the macros that turns it into more than just a spreadsheet.

    The code I posted above is in the .xlam file.

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

    Re: VBA Run-time error ‘91’: Object variable or With block variable not set

    When you debug the code where is it located?

    Is it in the ThisWorkbook module of a particular workbook/add-in?

    Are there any workbooks other than the one you've just opend listed in the Project Explorer?

    What is the code meant to do?

  15. #15
    Registered User
    Join Date
    10-24-2014
    Location
    Vancouver, BC
    MS-Off Ver
    2013
    Posts
    7

    Re: VBA Run-time error ‘91’: Object variable or With block variable not set

    The code with the error is listed under TTV2.xlam > Microsoft Excel Objects > ThisWorkbook

    It is meant to activate a number of macros that compile data into prebuilt forms

    The .xlsm file also has a ThisWorkbook module listed under Microsoft Excel Objects

+ 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. Replies: 0
    Last Post: 04-16-2013, 07:15 AM
  2. Replies: 6
    Last Post: 12-21-2012, 08:03 AM
  3. Replies: 1
    Last Post: 09-25-2012, 08:03 PM
  4. [SOLVED] Intermittent Run-time Error 91: Object Variable or With Block variable not set
    By fraanchtoast in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 08-29-2012, 10:11 AM
  5. Run Time Error 91, Object Variable or With Block Variable not set
    By chrisnz1947 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-05-2011, 06:29 AM

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