由于activewoorkbook.close true
我的宏打开了saveFileDialog,但它默认选择其保存类型为“Excel Workbook”。我需要更改为“excel 97-2003工作簿”。即使我在excel保存选项中更改了我的默认格式。但它只有在我手动保存文件时才有效。任何人都可以建议我一些线路吗?
Sub OpenAllWorkbooksnew() 设置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
答案 0 :(得分:2)
您可以调用SaveAs方法(使用DisplayAlerts = False)而不是Close。首先更改目标目录,然后在SaveAs中指定文件格式。这对你有帮助吗?
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
答案 1 :(得分:2)
我不知道我是否理解。您可以先显示文件对话框,在其中获取文件名及其路径,然后调用save-as方法。
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
或者这样你只需显示另存为对话框:
Application.Dialogs(xlDialogSaveAs).Show "c:\temp\VBA\test\test.xls"