Hello,
I have macro that exports from Excel and saves to csv in the same location as the original file. I'm finding this is problamatic as some users save the original file in different locations.
I would like to have the macro save the csv file in only one location (and overwrite the old file).
Here is what I have so far:
So instead of
I need to export to only one file location: H:\Connected Files\Excel\File
Any help is appeciated!
I have macro that exports from Excel and saves to csv in the same location as the original file. I'm finding this is problamatic as some users save the original file in different locations.
I would like to have the macro save the csv file in only one location (and overwrite the old file).
Here is what I have so far:
VBA Code:
Sub ExportAsCSV()
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:=xlCSV, CreateBackup:=False, Local:=True
TempWB.Close SaveChanges:=False
Application.DisplayAlerts = True
End Sub
So instead of
VBA Code:
MyFileName = CurrentWB.Path & "\" & CurrentWB.ActiveSheet.Name & ".csv"
I need to export to only one file location: H:\Connected Files\Excel\File
Any help is appeciated!