Results 1 to 7 of 7

Use VBA to open workbook without running macros?

This is a discussion on Use VBA to open workbook without running macros? within the Excel Questions forums, part of the Question Forums category; Greetings, I need to use VBA to open a workbook with macros disabled. How can I do this? Thanks, --Doug...

  1. #1
    Board Regular markadon's Avatar
    Join Date
    Feb 2007
    Location
    South Carolina
    Posts
    193

    Default Use VBA to open workbook without running macros?

    Greetings,

    I need to use VBA to open a workbook with macros disabled. How can I do this?

    Thanks,
    --Doug

  2. #2
    MrExcel MVP
    Moderator
    Smitty's Avatar
    Join Date
    May 2003
    Location
    Crested Butte, CO
    Posts
    27,261

    Default Re: Use VBA to open workbook without running macros?

    You don't.
    Smitty

    Every once in a while, there's a sudden gust of gravity...

    Check out my new book at the Mr. Excel Bookstore!

    Mr. Excel HTML Maker - Post a shot of your sheet

  3. #3
    MrExcel MVP
    Int'l Moderator
    Greg Truby's Avatar
    Join Date
    Jun 2002
    Location
    39 17' 15" N, -94 40' 26" W
    Posts
    9,770

    Default Re: Use VBA to open workbook without running macros?

    Don't have time to test this idea. But you might be able to shell out to the Excel.exe command and use the /s switch to open in safe mode... Just a thought.

    Maybe you can sweet talk Smitty into trying!
    Greg

    Work: XL 2003, 2007 and 2010 on Windows 7
    Please use CODE tags - especially for longer excerpts of code.

  4. #4
    Board Regular markadon's Avatar
    Join Date
    Feb 2007
    Location
    South Carolina
    Posts
    193

    Default Re: Use VBA to open workbook without running macros?

    A friend found this solution:

    Use Application.EnableEvents = False to disable the macros (and other events) then turn it back on when finished.

    Works for me!

  5. #5
    MrExcel MVP
    Moderator
    RoryA's Avatar
    Join Date
    May 2008
    Location
    East Sussex
    Posts
    22,859

    Default Re: Use VBA to open workbook without running macros?

    That's not quite the same as what you asked for though. That opens the workbook without running any event code - any macros within the workbook are not disabled.

  6. #6
    MrExcel MVP
    Int'l Moderator
    Greg Truby's Avatar
    Join Date
    Jun 2002
    Location
    39 17' 15" N, -94 40' 26" W
    Posts
    9,770

    Default Re: Use VBA to open workbook without running macros?

    Quote Originally Posted by markadon View Post
    Application.EnableEvents = False
    I too thought of that (and I'm sure Smitty did too). But I didn't mention it because, as Rory said, it's not quite what the OP asked for. It is worth noting that turning off events, would indeed keep macros from executing upon the opening of the other workbook because workbooks opened programmatically do not execute the Auto_Open() method (see here for more info).
    Greg

    Work: XL 2003, 2007 and 2010 on Windows 7
    Please use CODE tags - especially for longer excerpts of code.

  7. #7
    MrExcel MVP
    Moderator
    Smitty's Avatar
    Join Date
    May 2003
    Location
    Crested Butte, CO
    Posts
    27,261

    Default Re: Use VBA to open workbook without running macros?

    I too thought of that (and I'm sure Smitty did too).
    I had thought of that as well, but as Greg points out as it wasn't what was specifically asked for, I didn't mention it.

    If you'd said "I have two workbooks, both with macros. I want #1 to open #2, but I don't want #2's code to run when it's opened by #1." I think we would have been on board right away.
    Smitty

    Every once in a while, there's a sudden gust of gravity...

    Check out my new book at the Mr. Excel Bookstore!

    Mr. Excel HTML Maker - Post a shot of your sheet

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com