如何使用 vba 在 excel2010 中将保存类型从 excel 工作簿更改为 excel 97-2003?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14828146/
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
How to change save type from excel workbook to excel 97-2003 in excel2010 using vba?
提问by user1960257
Due to activewoorkbook.close true
my macro opens saveFileDialog but it select its save type by default as "Excel Workbook". which i need to change as "excel 97-2003 workbook".even i have changed my default format in excel save options. but it works only when i save file manualy. can any one suggest me some line?
由于activewoorkbook.close true
我的宏打开 saveFileDialog 但它默认选择其保存类型为“Excel 工作簿”。我需要将其更改为“excel 97-2003 工作簿”。即使我已经更改了 excel 保存选项中的默认格式。但它只有在我手动保存文件时才有效。任何人都可以给我一些建议吗?
Sub OpenAllWorkbooksnew() Set destWB = ActiveWorkbook Dim DestCell As Range
Sub OpenAllWorkbooksnew() Set destWB = ActiveWorkbook Dim DestCell As Range
Dim cwb As Workbook
For Each cwb In Workbooks
**Call donemovementReport**
ActiveWorkbook.Close True
ActiveWorkbook.Close False
Next cwb
End Sub
回答by dee
You could call the SaveAs method (with DisplayAlerts = False) instead of Close. First change the target directory and in SaveAs specify the file format. Does this help you?
您可以调用 SaveAs 方法(使用 DisplayAlerts = False)而不是 Close。首先更改目标目录并在另存为中指定文件格式。这对你有帮助吗?
Dim targetDirectory As String
targetDirectory = "c:\temp\VBA\test\"
ChDir targetDirectory
Application.DisplayAlerts = False
Workbooks(ActiveWorkbook.Name).SaveAs ActiveWorkbook.Name, xlExcel8
Application.DisplayAlerts = True
ActiveWorkbook.Close False
回答by dee
Well I do not know if I understand. You could first display the file-dialog where you get the file name with its path and then call save-as method.
好吧,我不知道我是否理解。您可以首先显示文件对话框,在其中获取文件名及其路径,然后调用另存为方法。
Sub test2()
Dim targetDirectory As String
targetDirectory = "c:\temp\VBA\test\"
ChDir targetDirectory
Dim excelFileName As Variant
excelFileName = Application.GetSaveAsFilename(FileFilter:="Excel Files,*.xls,All Files,*.*", Title:="Save As File Name")
If excelFileName = False Then Exit Sub
If LCase$(Right$(excelFileName, 4)) <> ".xls" Then
excelFileName = excelFileName & ".xls"
End If
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs fileName:=excelFileName, FileFormat:=xlExcel8
Application.DisplayAlerts = True
ActiveWorkbook.Close False
End Sub
Or this way you can just display the save-as dialog:
或者这样你就可以只显示另存为对话框:
Application.Dialogs(xlDialogSaveAs).Show "c:\temp\VBA\test\test.xls"