ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Disabling Macros (https://www.excelbanter.com/excel-programming/323954-disabling-macros.html)

Greg

Disabling Macros
 
I have a workbook (with several worksheets). One of the worksheets just
contains information explaining the use and functionality of the workbook.
How can I stop a user from trying to run the macro when the informational
sheet is active? MY first attempt was to create a private sub on the
worksheet and use Application.OnKey and trap the macro's I do not want the
user to run. Excel blew up and abended abnormally.

Ron de Bruin

Disabling Macros
 
Hi Greg

You can use something like this

Sub test()
If ActiveSheet.Name = "Sheet1" Then
'do nothing
Else
MsgBox "Your code"
End If
End Sub





--
Regards Ron de Bruin
http://www.rondebruin.nl



"Greg" wrote in message ...
I have a workbook (with several worksheets). One of the worksheets just
contains information explaining the use and functionality of the workbook.
How can I stop a user from trying to run the macro when the informational
sheet is active? MY first attempt was to create a private sub on the
worksheet and use Application.OnKey and trap the macro's I do not want the
user to run. Excel blew up and abended abnormally.




Tom Ogilvy

Disabling Macros
 
I would recommend a low tech, low maintenance solution such as:

Sub MyMacro()
if lcase(sh.Name) = "Intro" then exit sub
' existing code
End sub

Using something to check that is guaranteed not to change might be better
than the sheet name. It could also be a positive check - check for the
sheet you want you macro to run on.

--
Regards,
Tom Ogilvy


"Greg" wrote in message
...
I have a workbook (with several worksheets). One of the worksheets just
contains information explaining the use and functionality of the workbook.
How can I stop a user from trying to run the macro when the informational
sheet is active? MY first attempt was to create a private sub on the
worksheet and use Application.OnKey and trap the macro's I do not want the
user to run. Excel blew up and abended abnormally.





All times are GMT +1. The time now is 06:17 AM.

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