VBA 文件格式保存为 .xls

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29753833/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 09:32:49  来源:igfitidea点击:

VBA FileFormat to save as .xls

excelexcel-vbavba

提问by Mark Smith

I have a macro to save the active worksheet to a new workbook. However it wants to save it as .xlsx and I need it to save as .xls

我有一个宏可以将活动工作表保存到新工作簿。但是它想将它保存为 .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

回答by Aaron Thomas

The ActiveWorkbook.SaveAs methodhas a member that allows different file formats: XlFileFormat Enumeration. There are several formats available through this beside .xlsx, including .xls.

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

Please note that MSDN's article on .SaveAs (first link above) says "For an existing file, the default format is the last file format specified; for a new file, the default is the format of the version of Excel being used."

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