Note: I'm too basic in VBA/macros...
I have a macro that exports my sheet as CSV without leaving the XLSM file, that works great:
I just need to run it automatically each time I save my sheet...
It´s possible?? How to do it?
Thanks in advance! =)
I have a macro that exports my sheet as CSV without leaving the XLSM file, that works great:
VBA Code:
Sub ExportCSV()
Dim MyFileName As String
Dim CurrentWB As Workbook, TempWB As Workbook
Set CurrentWB = ActiveWorkbook
ActiveWorkbook.ActiveSheet.UsedRange.Copy
Set TempWB = Application.Workbooks.Add(1)
With TempWB.Sheets(1).Range("A1")
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
End With
MyFileName = CurrentWB.Path & "\" & Left(CurrentWB.Name, InStrRev(CurrentWB.Name, ".") - 1) & ".csv"
'Optionally, comment previous line and uncomment next one to save as the current sheet name
'MyFileName = CurrentWB.Path & "\" & CurrentWB.ActiveSheet.Name & ".csv"
Application.DisplayAlerts = False
TempWB.SaveAs Filename:=MyFileName, FileFormat:=xlCSVUTF8, CreateBackup:=False, Local:=False
TempWB.Close SaveChanges:=False
Application.DisplayAlerts = True
End Sub
I just need to run it automatically each time I save my sheet...
It´s possible?? How to do it?
Thanks in advance! =)