WorkbookBeforeSave Problem

S

Steve

Excel 2007

I copied two macro examples from the Excel Help File and tried to run them,
but I get an error message that says:


Cannot run the macro ‘MacroName.xlsm’. The macro may not be available in
this workbook or all macros may be disabled.

I have enabled all macros. But still get that message.
The macro is in my Personal.xls file in the XLSTART folder. And even when I
open THAT file and try to run the macro, it doesn't work. Same message.

The macros I have copied from Help (there are two) are:

Option Explicit
Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook, _
ByVal SaveAsUI As Boolean, Cancel As Boolean)
a = MsgBox("Do you really want to save the workbook?", vbYesNo)
If a = vbNo Then Cancel = True
End Sub

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
a = MsgBox("Do you really want to save the workbook?", vbYesNo)
If a = vbNo Then Cancel = True
End Sub


Please help.
Thanks
 
S

Simon Lloyd

Take a look at TOOLS>MACRO>MACROS or Alt+F8 left click a macro once
look at the "Macros In" box there is a dropdown, it reads "all ope
workbooks", "This workbook" & "My Workbook" where My Workbook would b
the name of your workbook" if your macro is situated in another workboo
you macro name will look like this *Book2!Macro2 *look in the drop dow
and you should also see *Book2*, change the macro to be available in al
open workbooks

Steve;544230 said:
Excel 200

I copied two macro examples from the Excel Help File and tried to ru
them
but I get an error message that says


Cannot run the macro ‘MacroName.xlsm’. The macro may not b
available i
this workbook or all macros may be disabled

I have enabled all macros. But still get that message
The macro is in my Personal.xls file in the XLSTART folder. And eve
when
open THAT file and try to run the macro, it doesn't work. Same message

The macros I have copied from Help (there are two) are

Option Explici
Private Sub App_WorkbookBeforeSave(ByVal Wb As Workbook,
ByVal SaveAsUI As Boolean, Cancel As Boolean
a = MsgBox("Do you really want to save the workbook?", vbYesNo
If a = vbNo Then Cancel = Tru
End Su

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean,
Cancel As Boolean
a = MsgBox("Do you really want to save the workbook?", vbYesNo
If a = vbNo Then Cancel = Tru
End Su


Please help
Thank

--
Simon Lloy

Regards
Simon Lloy
'Microsoft Office Help' (http://www.thecodecage.com
 
G

Gord Dibben

Those are events that run automatically when the workbook closes or is
saved.

They are not macros that you "run".

They have no names and cannot be run manually.

Must be placed into the Thisworkbook module of whatever workbook you want
them to run from.

They will not run from Personal.xls on any other workbook.


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top