Forum

Run macro with save...
 
Notifications
Clear all

Run macro with save button (Ctrl+S)

4 Posts
2 Users
0 Reactions
938 Views
 Rafi
(@rafi1470gmail-com)
Posts: 9
Active Member
Topic starter
 

Hi,

I have one macro where i want to run the macro with save button instead of clicking "Run button" every time.

Below is my very small coding, i want to add some coding to run the macro whenever i save the file (Ctrl+S).

 

Sub Numberformat()
'
' Numberformat Macro
'
Columns("J:M").Select
Selection.Numberformat = "General"

Columns("J:J").Select
Selection.TextToColumns Destination:=Range("J1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
:=Array(1, 2), TrailingMinusNumbers:=True

End Sub

 
Posted : 06/02/2020 4:18 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Rafi,

Use a Workbook_BeforeSave event

 

   Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

       << YOUR CODE GOES HERE  >>

   End Sub

 

This code will go in the ThisWorkbook module of your workbook - see attached.

Regards

Phil

 
Posted : 06/02/2020 7:13 pm
 Rafi
(@rafi1470gmail-com)
Posts: 9
Active Member
Topic starter
 

Hi Philip,

If i use your file, it is working 100%. Thanks a lot for your help.

I need one more help from you. I have attached my file with your coding. But this file is not working properly. Can you help me where it went wrong?

 
Posted : 08/02/2020 3:20 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Rafi,

This code will go in the ThisWorkbook module of your workbook - see attached.

Event code doesn't go in a 'normal' code module.

Regards

Phil

 
Posted : 08/02/2020 10:06 pm
Share: