BeforeSave xl

royinfo

New Member
Joined
Nov 18, 2009
Messages
5
I have an XL Purchase Order sheet that customer's can fill only Unlocked cells.

At the end he must do Save or Save AS and send it to me by Email.

At the moment he's doing Save or Save As, I would like to execute something.

To test it I wrote that little macro :

Sub macro1()
'
' Macro1 Macro
' Macro recorded 18/11/2009 by administrator
'
MsgBox ("macro1")
'
End Sub


Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
MsgBox ("BeforeSave")
End Sub


If I'm doing Save or Save no Msg appear.. Why ?<M Why Save) the during appear MSG no ( working not is As Save or doing p ?<>

THANK YOU for your help. <!-- / message --><!-- BEGIN TEMPLATE: ad_showthread_firstpost_sig --><!-- END TEMPLATE: ad_showthread_firstpost_sig -->
 
Last edited:

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Is the BeforeSave code on the ThisWorkbook page of the workbook's VBA project?

All workbook level event code needs to place on there to execute.

Dom
 
Upvote 0
Hello Domski,

First, with macro I'm Dummmmmmy.

The only think that I have done is :

1- Open my Purchase Order Xl sheet
2- Create a new Macro (Macro in = This Workbook) and include the code into it.
3- Save everythings
4- Close everythings
5- Reopen my Purchase Order Sheet and tried to execute my Save procedure.

Thanks
 
Upvote 0
The code you have recorded will have been placed in a Module within the Workbook's VBA project. Modules are the normal place to put code that you want to execute yourself.

Event code that runs automatically needs to be placed in a specific place depending on the type of event that you want to trigger.

The Workbook_BeforeSave code that you quoted works at the Workbook level and therefore needs to be placed in the ThisWorkbook code page of the VBA Project.

This gives a good overview of event codes if you are interested: http://www.cpearson.com/excel/Events.aspx

Dom
 
Upvote 0
Thanks Domski,

I'm in VBA Project and add the BeforeSave event.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
MsgBox ("Do you really want to save the workbook?")

End Sub

That event switch automatically into General and not into Worksheet.

I save everything and tried to save the xl sheet and the beforesave event not work..
 
Upvote 0
You have to put the code on the ThisWorkbook code page. It should then show you a message each time you select Save, it won't do anything else.

Dom
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,192
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top