将工作表另存为.CSV文件

我必须复制数据并将其粘贴到新工作表中,并根据用户需求更改工作表名称,并将其保存在相同的名称中。我写了代码并执行了,但是我无法在指定的位置find该文件。请帮我解决这个问题。

Sub saveascsv() Dim Rng As Range Dim filenam As Variant Dim saveasfile As Variant filenam = InputBox("Enter name of the file to be saved") Set Rng = Range("E1:H" & Range("H" & Rows.Count).End(xlUp).Row) Rng.Select Selection.Copy ActiveWorkbook.Sheets.Add after:=Worksheets("Part_Number") ActiveSheet.Name = filenam ActiveSheet.Paste ActiveSheet.Columns("A:D").AutoFit Application.CutCopyMode = False saveasfile = Application.GetSaveAsFilename(InitialFileName:=filenam, FileFilter:="CSV (Comma delimited) (*.csv), *.csv", Title:="Save As") If saveasfile <> "False" Then MsgBox "saveas " & filenam End If End Sub 

你没有保存任何东西,只是获取文件的名称来保存和显示一个消息框。

 If saveasfile <> "False" Then ActiveSheet.move ' <-- Add this line ActiveSheet.SaveAs saveasfile, xlCSV ' <-- Add this line MsgBox "saved as " & saveasfile End If