Hello There,
I came across a procedure which creates a csv file based on a given range in worksheet. However, it creates a blank line at the end of file which I would like to delete it.
Could you please advice how this can be done with the VBA code?
Thank you & regards,
Don
Thak you
I came across a procedure which creates a csv file based on a given range in worksheet. However, it creates a blank line at the end of file which I would like to delete it.
Could you please advice how this can be done with the VBA code?
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, Len(CurrentWB.name) - 5) & ".csv"
Application.DisplayAlerts = False
TempWB.SaveAs filename:=MyFileName, FileFormat:=xlCSV, CreateBackup:=False, Local:=True
TempWB.Close SaveChanges:=False
Application.DisplayAlerts = True
End Sub
Thank you & regards,
Don
Thak you