Hi Everyone,
I have figured out some code to copy all the data from a table, create a new workbook, paste the data and then save the workbook as a CSV as the name of the original table the data came from. I now am trying to figure out how to save the file as a custom name from cell L23 from the original workbook. Any help would be appreciated.
Thank you in Advance
Sub ExportTableToCSVFile()
Dim wb As Workbook, wbNew As Workbook
Dim ws As Worksheet, wsNew As Worksheet
Dim wbNewName As String
Set wb = ThisWorkbook
Set ws = ActiveSheet
Set wbNew = Workbooks.Add
With wbNew
Set wsNew = wbNew.Sheets("Sheet1")
wbNewName = ws.ListObjects(1).Name
ws.ListObjects(1).DataBodyRange.Copy
wsNew.Range("A1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
.SaveAs Filename:=wb.Path & "" & wbNewName & ".csv", _
FileFormat:=xlCSVMSDOS, CreateBackup:=False
End With
ActiveWorkbook.Close SaveChanges:=True
End Sub
I have figured out some code to copy all the data from a table, create a new workbook, paste the data and then save the workbook as a CSV as the name of the original table the data came from. I now am trying to figure out how to save the file as a custom name from cell L23 from the original workbook. Any help would be appreciated.
Thank you in Advance
Sub ExportTableToCSVFile()
Dim wb As Workbook, wbNew As Workbook
Dim ws As Worksheet, wsNew As Worksheet
Dim wbNewName As String
Set wb = ThisWorkbook
Set ws = ActiveSheet
Set wbNew = Workbooks.Add
With wbNew
Set wsNew = wbNew.Sheets("Sheet1")
wbNewName = ws.ListObjects(1).Name
ws.ListObjects(1).DataBodyRange.Copy
wsNew.Range("A1").PasteSpecial Paste:=xlPasteValuesAndNumberFormats
.SaveAs Filename:=wb.Path & "" & wbNewName & ".csv", _
FileFormat:=xlCSVMSDOS, CreateBackup:=False
End With
ActiveWorkbook.Close SaveChanges:=True
End Sub