[英]Saving excel worksheet to CSV with file name from a cell using a macro
i have a macro that saves a copy of my workbook that works but it saves as a .xlsm and i need it to be saved as a comma delimited .csv file type can any one help me? 我有一个宏,可以保存工作簿的副本,但可以将其保存为.xlsm,并且我需要将其另存为以逗号分隔的.csv文件类型,有谁可以帮助我吗?
here is the macro i have now 这是我现在拥有的宏
Sub toCSV()
子到CSV()
Dim newWB As Variant Dim wb1 As Workbook Set wb1 = ActiveWorkbook With wb1 .SaveCopyAs ("C:\\Users\\sales\\desktop\\") & Range("A2").Text & ".xlsm" End With End Sub
This code will take the sheet you want to be saved as a CSV, and copy it to a new workbook before saving 此代码会将您想要保存为CSV的工作表,并在保存之前将其复制到新工作簿中
Dim CSVBook As Workbook
Set CSVBook = Workbooks.Add
ThisWorkbook.Sheets("TheCSVSheet").Copy Before:=CSVBook.Sheets(1)
CSVBook.SaveAs Filename:="C:\tmp\test.csv", FileFormat:=xlCSV
CSVBook.Close
This will allow you to save the file as a CSV, but still retain the original macro enabled spreadsheet which you can go back to, and do whatever other processing you need 这将使您可以将文件另存为CSV,但仍保留原始的启用了宏的电子表格,您可以返回该电子表格,并进行所需的其他处理
.SaveAs Filename:=("C:\Users\sales\desktop\") & Range("A2").Text & ".csv", _
FileFormat=:xlCSV
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.