Assign a macro to the save button

J

Jonno

Hi,

I have just learnt how to use macro's and i was wondering if you could
assign the macro so it runs everytime I press the save button.

I would only want the macro to work on this worksheet, no others!!!

Here is my macro below (Very simple), to protect all work sheets when the
button is pressed. But i would like this to be assign to the save button

Sub Macro3()
'
' Macro3 Macro
'

'
Sheets("Sheet3").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Sheets("Sheet2").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
Sheets("Sheet1").Select
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub

Hope you can help!!!!!
 
J

Jacob Skaria

From workbook launch VBE using short-key Alt+F11. On the left treeview under
'VBA Project(workbookname.xls)> Microsoft Excel Objects> double click 'This
Workbook' and paste the below code to the code panel.

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Call Macro3
End Sub

This is the BeforeSave event which triggers just before you save the
workbook. Call Macro3 will call your macro which exists in one of the
modules..of the same workbook

If this post helps click Yes
 
J

Jonno

This works great thank you very much.

What would i do if i wanted to add more macros before saving I.e Macro 1 or
2, or both aswell?
 
J

Jacob Skaria

Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Call Macro1
Call Macro2
Call Macro3
End Sub

If this post helps click Yes
 
J

Jonno

Great thank you very much!!!!!
--
Jonno


Jacob Skaria said:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
Call Macro1
Call Macro2
Call Macro3
End Sub

If this post helps click Yes
 

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