0

由于activewoorkbook.close true我的宏打开 saveFileDialog 但它默认选择其保存类型为“Excel Workbook”。我需要将其更改为“excel 97-2003 工作簿”。即使我在 excel 保存选项中更改了我的默认格式。但它仅在我手动保存文件时才有效。谁能给我一些建议?

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
4

2 回答 2

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
于 2013-02-12T09:29:28.600 回答
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"
于 2013-02-14T11:57:16.743 回答