ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Run Macro Before Save (https://www.excelbanter.com/excel-programming/368699-run-macro-before-save.html)

RigasMinho

Run Macro Before Save
 
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


Die_Another_Day

Run Macro Before Save
 
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



RigasMinho

Run Macro Before Save
 
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



Die_Another_Day

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




All times are GMT +1. The time now is 11:46 AM.

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