VBA FileFormat保存为.xls

我有一个macros将活动工作表保存到一个新的工作簿。 但是,它想要将其保存为.xlsx,我需要它保存为.xls

Private Sub SaveBarList_Click() ActiveSheet.Copy With ActiveSheet.UsedRange .Copy .PasteSpecial xlValues .PasteSpecial xlFormats End With Dim strDir As String 'Show standard save as dialogue box With Application.FileDialog(msoFileDialogSaveAs) If .Show = -1 Then strDir = .SelectedItems(1) End If End With Application.DisplayAlerts = False ActiveWorkbook.SaveAs Filename:=Application.GetSaveAsFilename, FileFormat:=-4143 Application.DisplayAlerts = True ActiveWorkbook.Close End Sub 

ActiveWorkbook.SaveAs方法有一个允许不同文件格式的成员: XlFileFormat枚举 。 在.xlsx旁边有几种可用的格式,包括.xls。

请注意,MSDN关于.SaveAs的文章(上面的第一个链接)说:“对于现有文件,默认格式是指定的最后一种文件格式;对于新文件,默认格式是正在使用的Excel版本格式。