+ Reply to Thread
Results 1 to 12 of 12

open a file programically and disable macros

  1. #1
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    open a file programically and disable macros

    When I have a macro open another file, it always activates the macros in it. Is there some way to disable the macros?
    Last edited by foxguy; 06-30-2009 at 05:42 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: open a file programically and disable macros

    Please Login or Register  to view this content.
    This code in your macro should disable other macros from firing until you issue a "TRUE" version later.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    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: open a file programically and disable macros

    That will keep events from triggering in the open workbook.

    If you don't want macros to be able to run at all in the workbook (e.g., via Alt+F8), then before opening,
    Please Login or Register  to view this content.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: open a file programically and disable macros

    replied too soon
    Last edited by foxguy; 06-30-2009 at 05:47 PM.

  5. #5
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: open a file programically and disable macros

    shg;

    I tried this code:
    Please Login or Register  to view this content.
    and my macro just ended as soon as the file was opened. It never reached the line that reset the AutomationSecurity.
    The file opened fine and macros would not run in it, but the security was not reset.

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: open a file programically and disable macros

    Try this
    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  7. #7
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: open a file programically and disable macros

    Quote Originally Posted by royUK View Post
    Try this
    Please Login or Register  to view this content.
    Am I reading that right? 2 "Sub" statements, but only 1 "End Sub". If that's just a typo, how is it different from what I already tried?

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: open a file programically and disable macros

    Sorry, I copied & pasted in a rush, then made amendments. You don't declare the variable, when I run the code it disables the code within the opened workbook but not the parent workbook.

  9. #9
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: open a file programically and disable macros

    Roy;

    That's the same code I run (I declare the variable, just didn't put it in the reply). But when it opens the workbook, the macro ends. It never executes the line:
    Please Login or Register  to view this content.

  10. #10
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: open a file programically and disable macros

    Try attaching the workbook, it worked for me in a dummy workbook

  11. #11
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,247

    Re: open a file programically and disable macros

    How are you running the code as a matter of interest?
    Remember what the dormouse said
    Feed your head

  12. #12
    Forum Expert
    Join Date
    03-31-2009
    Location
    Barstow, Ca
    MS-Off Ver
    Excel 2002 & 2007
    Posts
    2,164

    Re: open a file programically and disable macros

    Quote Originally Posted by romperstomper View Post
    How are you running the code as a matter of interest?
    I created a menu button that executes a macro that opens the file.

+ 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