MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Disable macros in a workbook


Posted by Sam on May 20, 2001 8:56 AM

Hello Folks,
I'm saving workbooks that contain Macros that run when the workbook opens. These workbooks are saved as different filenames other than the open workbook file name to another location other than where the orginal workbook is stored. Is there a way to disable the macros in the workbooks that are stored in the different location to keep them from running if the workbook is opened for let's say, edit purposes.
Thanks, Sam


Posted by Dax on May 20, 2001 9:12 AM

Why not have the macros set up to not autorun when the workbook is open. Then use something like this when you are opening the workbook where you actually want the macros to execute: -

Private Sub Workbook_Open()
Application.Workbooks.Open "C:\windows\temp\testbook.xls", , True
Application.Run "TestBook.xls!TestMacro"

HTH,
Dax.

Posted by Dave Hawley on May 20, 2001 9:30 AM

Hi Sam

All you should need is a small one liner to check the name and path of the Workbook as it Opens, eg;

Private Sub Workbook_Open()
If Me.FullName <> "C:\MyDocuments\Book1.xls" Then Exit Sub
'Your normal code.
End Sub

Dave
OzGrid Business Applications