简体   繁体   English

VBA文件格式另存为.xls

[英]VBA FileFormat to save as .xls

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

The ActiveWorkbook.SaveAs method has a member that allows different file formats: XlFileFormat Enumeration . ActiveWorkbook.SaveAs方法具有一个允许使用不同文件格式的成员: XlFileFormat枚举 There are several formats available through this beside .xlsx, including .xls. .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版本的格式。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM