且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用宏将excel工作表保存到带有文件名的CSV文件

更新时间:2022-10-23 21:24:07

代码:



  .SaveAs文件名: C:\Users\sales\desktop\)&范围(A2)。 .csv,_ 
FileFormat =:xlCSV


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?

here is the macro i have now

Sub toCSV()

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

Code:

.SaveAs Filename:=("C:\Users\sales\desktop\") & Range("A2").Text & ".csv", _
FileFormat=:xlCSV