zappedagain
Electrical
- Jul 19, 2005
- 1,074
I have a simple macro set up to automatically save a file in CSV format. How do I automatically call this macro when Save, Exit, or Close is selected?
I found the Workbook_beforeClose event but what do I do with it? The following doesn't do anything:
Sub SaveAsCSV()
'
' SaveAsCSV Macro
' Macro to save as CSV on exit.
'
'
ActiveWorkbook.SaveAs Filename:= _
"C:\file.csv", _
FileFormat:=xlCSV, CreateBackup:=False
ActiveWorkbook.Close
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Me.Saved = False Then Me.Save: SaveAsCSV
End Sub
Where do I need to put the Workbook_BeforeClose part?
Thanks for helping this Visual Basic newbie!
I found the Workbook_beforeClose event but what do I do with it? The following doesn't do anything:
Sub SaveAsCSV()
'
' SaveAsCSV Macro
' Macro to save as CSV on exit.
'
'
ActiveWorkbook.SaveAs Filename:= _
"C:\file.csv", _
FileFormat:=xlCSV, CreateBackup:=False
ActiveWorkbook.Close
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Me.Saved = False Then Me.Save: SaveAsCSV
End Sub
Where do I need to put the Workbook_BeforeClose part?
Thanks for helping this Visual Basic newbie!