View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Die_Another_Day Die_Another_Day is offline
external usenet poster
 
Posts: 644
Default Run Macro Before Save

No. in the "Project" Explorer you will see VBAProject(YourWorkbook.xls)
Expand that.
Now you should see Microsoft Excel Objects
Expand that
Now there should be a "This Workbook" item
double click that
That should open a code window with 2 comboboxes at the top
in the left combobox select "Workbook"
in the right combobox select "BeforeSave"
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)

End Sub

Those 2 lines should appear for you. Paste the other lines in between

Die_Another_Day
RigasMinho wrote:
I found this:

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


Where would I put this code? In the general part of the workbook?


Die_Another_Day wrote:
Check out the BeforeSave Event under the "ThisWorkbook" in MicroSoft
Excel Objects in the VBA Editor

Die_Another_Day
RigasMinho wrote:
Is there a way to run a macro each time before you hit the save button.

Meaning if you go to file - save - it runs the macro instead of saving
the file
or if you hit control +s it runs the macro instead of saving the file


Let me know thanks