+ Reply to Thread
Results 1 to 7 of 7

Enabling Macros in Multiple Session of Excel

  1. #1
    Registered User
    Join Date
    01-20-2010
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    18

    Enabling Macros in Multiple Session of Excel

    I am using the code below to open multiple workbooks in their own instance of Excel. On my system, as well as most of the ones I've tested it on, enabling macros in the "parent" workbook, i.e. the one that contains the code, leaves them automatically enabled in the new session of Excel, as though the settings are carried over. However, recently I've found a few systems where this is not the case. Enabling macros in the parent workbook opens the others, and then I have to enable macros again in each of the new sessions. Is there a way to fix this? All of the systems mentioned above have macro settings set to "disable with notification" and this cannot be changed.

    Thanks in advance,
    Kyle

    Please Login or Register  to view this content.
    Last edited by c_leven3; 02-18-2010 at 12:51 PM.

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

    Re: Enabling Macros in Multiple Session of Excel

    You should put Option Explicit at the top of your module, and then declare variables until your code compiles.

    On my system, as well as most of the ones I've tested it on, enabling macros in the "parent" workbook, i.e. the one that contains the code, leaves them automatically enabled in the new session of Excel,
    If macros weren't enabled in the workbook the code is in, you couldn't be running other macros to do anything, right?

    Macros in workbooks opened programatically in another Excel instance are controlled by the AutomationSecurity property of the Application object. See if reading about it in Help answers your question.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    01-20-2010
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Enabling Macros in Multiple Session of Excel

    Sorry. That was just one sub routine from my ThisWorkbook. This is at the very top:

    Please Login or Register  to view this content.
    And - I'll look into your suggestion. Thanks.

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

    Re: Enabling Macros in Multiple Session of Excel

    You could do this is a loop:
    Please Login or Register  to view this content.
    Last edited by shg; 02-17-2010 at 05:58 PM.

  5. #5
    Registered User
    Join Date
    01-20-2010
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Enabling Macros in Multiple Session of Excel

    I'm sorry, but I'm confused about what part of that will change the security settings in the programmatically opened workbooks?

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

    Re: Enabling Macros in Multiple Session of Excel

    Nothing.

    The default state for AutomationSecurity is msoAutomationSecurityLow, which means macros are enabled in workbooks opened programatically. You have to explicitly set it to msoAutomationSecurityForceDisable to disable macros, or msoAutomationSecurityByUI to have macros enabled/disabled according to UI settings.

  7. #7
    Registered User
    Join Date
    01-20-2010
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2007
    Posts
    18

    Re: Enabling Macros in Multiple Session of Excel

    Ok. Thanks for all your help. AutomationSecurity is exactly what I've been looking for.

+ 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