+ Reply to Thread
Results 1 to 10 of 10

Macro Won't Run Using Workbook_Open() When Macros Need Enabling

  1. #1
    Registered User
    Join Date
    04-29-2010
    Location
    MI
    MS-Off Ver
    Excel 2007
    Posts
    15

    Macro Won't Run Using Workbook_Open() When Macros Need Enabling

    Hello,

    I'm trying to run a macro using the event, Workbook_Open(). The problem I'm having is when I open the file I'm asked if I want to enable macros. After I click enable, the macro does not run. I would like to keep the same security level and not always allow macros for when I'm using Excel in a different manner.


    Thanks

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Macro Won't Run Using Workbook_Open() When Macros Need Enabling

    Workbook_Open code must be in the ThisWorkbook module.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    04-29-2010
    Location
    MI
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Macro Won't Run Using Workbook_Open() When Macros Need Enabling

    The macro I'm wanting to run must be in the ThisWorkbook module too then and can't be in an individual sheet?

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Macro Won't Run Using Workbook_Open() When Macros Need Enabling

    No, just the Workbook_Open code.

  5. #5
    Registered User
    Join Date
    04-29-2010
    Location
    MI
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Macro Won't Run Using Workbook_Open() When Macros Need Enabling

    I get a "Sub or Function not defined" error. OpenFile#_Click is in 4 different sheets.

    Please Login or Register  to view this content.

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Macro Won't Run Using Workbook_Open() When Macros Need Enabling

    I wouldn't do it that way.

    The click event in each sheet module should call a procedure in a code module, which you could also call from the ThisWorkbook module.

  7. #7
    Registered User
    Join Date
    04-29-2010
    Location
    MI
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Macro Won't Run Using Workbook_Open() When Macros Need Enabling

    I'm sorry, I'm not following. I have a button on Sheet 1 named OpenFile1. I have code in a sub called OpenFile1_Click() which is located in Sheet 1 under Microsoft Excel Objects. Is this not correct?

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Macro Won't Run Using Workbook_Open() When Macros Need Enabling

    Yes, that correct.

    Then there's code in each of those click events. That code, if it needs to be invoked from more than one place, should be placed in a CODE module, and called from both the Click event and the Workbook_Open event.

    Think of it this way: The Workbook_Open event isn't clicking the buttons, it's causing the same code to run as runs when you click the button.
    Last edited by shg; 05-25-2010 at 05:24 PM.

  9. #9
    Registered User
    Join Date
    04-29-2010
    Location
    MI
    MS-Off Ver
    Excel 2007
    Posts
    15

    Re: Macro Won't Run Using Workbook_Open() When Macros Need Enabling

    I'm wondering now if this will work because when I open my Excel sheet the event will never run the macro because I don't have macros enabled. Once I enable macros after opening the sheet the event would have already run. Is that correct?

    Thanks for all your help.

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Macro Won't Run Using Workbook_Open() When Macros Need Enabling

    If you disable macros, no macros run; if you enable them they do. What third alternative are you wondering about?

+ 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