+ Reply to Thread
Results 1 to 4 of 4

Macro has errors if Visual Basic Editor is not open

  1. #1
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Macro has errors if Visual Basic Editor is not open

    I've been helping another user create a workbook that dynamically adds, renames and deletes worksheets from a "Main Sheet".

    I have got the whole thing figured out and running to satisfaction, except...

    The macro runs fine if the Visual Basic Editor is open. If the editor is closed while the macro is run, I get "Runtime Error '9': Subscript out of range"

    Any ideas what could be casing this? The errors occur when attempting to add sheets.

    Here's my "UpdateAll" macro that is having the issues:

    Please Login or Register  to view this content.
    It seems to break-down here:
    Please Login or Register  to view this content.
    When it goes to update the Main Sheet with the new worksheet's codename, ActiveSheet.CodeName seems to be blank.

    Again, this only happens if the Visual Basic Editor is not open. It is as if excel cannot get the codename of a sheet if the editor is not open.

    Any help would be much appreciated.
    Attached Files Attached Files
    Last edited by Whizbang; 11-12-2009 at 02:48 PM.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Macro has errors if Visual Basic Editor is not open

    Try this routine
    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Expert Whizbang's Avatar
    Join Date
    08-05-2009
    Location
    Greenville, NH
    MS-Off Ver
    2010
    Posts
    1,395

    Re: Macro has errors if Visual Basic Editor is not open

    Thanks. Worked great.

  4. #4
    Registered User
    Join Date
    01-22-2022
    Location
    Birmingham, Alabama
    MS-Off Ver
    Office 365
    Posts
    1

    Re: Macro has errors if Visual Basic Editor is not open

    I had the same problem with Excel 365; only I wanted to return the CodeName of the active sheet,
    so I substituted ActiveWorkBook for ThisWorkBook and your solution worked great. Thanks

+ 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