ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Disable VBA code execution when loading a workbook (https://www.excelbanter.com/excel-discussion-misc-queries/37180-disable-vba-code-execution-when-loading-workbook.html)

Charles

Disable VBA code execution when loading a workbook
 
How do I control the execution of the VBA Code in a spread sheet when I first
load the workbook.
I would like a dialog box to ask if I want to execute the code or not whenI
open the workbook?
Can any one suggest a way to do that???
--
CharlesM

Anne Troy

Set your macro security to medium.
*******************
~Anne Troy

www.OfficeArticles.com


"Charles" wrote in message
...
How do I control the execution of the VBA Code in a spread sheet when I

first
load the workbook.
I would like a dialog box to ask if I want to execute the code or not

whenI
open the workbook?
Can any one suggest a way to do that???
--
CharlesM




Earl Kiosterud

Charles,

You could use a flag. In module ThisWorkbook:

Private Sub Workbook_Open()
If MsgBox("Do you want to run the macros?", vbYesNo, "Hey") = vbYes Then
MacRun = True
End Sub

Now in your macros you can test this switch to determine whether to do stuff
or not

In a general module

Public MacRun as Boolean ' This line must be before any subs,
' (and only in one module).

Sub whatever()
If not MacRun then exit sub
..
' your macro code
..
End sub
--
Earl Kiosterud
www.smokeylake.com

"Charles" wrote in message
...
How do I control the execution of the VBA Code in a spread sheet when I
first
load the workbook.
I would like a dialog box to ask if I want to execute the code or not
whenI
open the workbook?
Can any one suggest a way to do that???
--
CharlesM




AusTexRich

Security was at medium. Re-set to lowest and the same thing is happening.
--
AusTexRich


"Anne Troy" wrote:

Set your macro security to medium.
*******************
~Anne Troy

www.OfficeArticles.com


"Charles" wrote in message
...
How do I control the execution of the VBA Code in a spread sheet when I

first
load the workbook.
I would like a dialog box to ask if I want to execute the code or not

whenI
open the workbook?
Can any one suggest a way to do that???
--
CharlesM





AusTexRich

Thanks. I'll make good use of the code.
--
AusTexRich


"Earl Kiosterud" wrote:

Charles,

You could use a flag. In module ThisWorkbook:

Private Sub Workbook_Open()
If MsgBox("Do you want to run the macros?", vbYesNo, "Hey") = vbYes Then
MacRun = True
End Sub

Now in your macros you can test this switch to determine whether to do stuff
or not

In a general module

Public MacRun as Boolean ' This line must be before any subs,
' (and only in one module).

Sub whatever()
If not MacRun then exit sub
..
' your macro code
..
End sub
--
Earl Kiosterud
www.smokeylake.com

"Charles" wrote in message
...
How do I control the execution of the VBA Code in a spread sheet when I
first
load the workbook.
I would like a dialog box to ask if I want to execute the code or not
whenI
open the workbook?
Can any one suggest a way to do that???
--
CharlesM






All times are GMT +1. The time now is 09:45 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com