Unauthorised Use Of Macro

  • Thread starter Thread starter Paul Moles
  • Start date Start date
P

Paul Moles

I have an auto_close macro designed to reset toolbars etc.
once a user has finished with the workbook.

Is it possible to prevent users being able to run the
macro whilst the workbook is in use?

Many Thanks

Paul Moles
PS The code is protected using project properties, I am
trying to stop premature running.
 
Use the Workbook_BeforeClose event

Private Sub Workbook_BeforeClose(Cancel As Boolean)
auto_close macro here
End Sub

Lars Kofod
 
Correct, the user cannot run workbook_beforeclose. But have you ever
wondered why a user *can* run workbook_open directly from the VBE?
 
Hi Paul

What if the user want to have several open files simoultaneously ? I'd expect my toolbars
to look and work as always when I'm in the not-your-workbooks. Consider to use the
activate / deactivate events instead. Paste this in the ThisWorkbook module:

Private Sub Workbook_WindowActivate(ByVal Wn As Window)
MsgBox "Active"
End Sub

Private Sub Workbook_WindowDeactivate(ByVal Wn As Window)
MsgBox "Gone"
End Sub
 
I always assumed it was because Workbook_Open() has no arguments.

You can certainly run this from the VBE:

Public Sub try()
Workbook_BeforeClose True
End Sub
 
Back
Top