VBA: 从 .xls 切换到 .xlsx 文件格式

3
我正在处理一个最初编写用来输出 .xls Excel 文件的数据库。我们需要将它改成 .xlsx,但我无法弄清楚如何实现。我尝试简单地将 ".xls" 改为 ".xlsx",但这并没有起作用。在 Set wbk= XLapp.Workbooks.Open(SavePath).Sheets(1) 这行代码处生成了一个错误——至少是调试器突出显示的。以下是当前代码部分:
Private Sub ExcelFeederReview_Click()
Dim SavePath As String
SavePath = fGetMyDocsPath & "\FeederReview_" & Format(Now, "YYYYMMDD_hhnn") & ".xls"
'Run Query and export to Savepath
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "qFeederExport", SavePath, False, "FeederReview"

'Open query in excel shell
Set XLapp = New Excel.Application
Set wbk = XLapp.Workbooks.Open(SavePath).Sheets(1)

'Format excel doc with excel shell
    With XLapp
            .Application.DisplayAlerts = False
            .Application.Rows("1:1").Select
            .Application.Selection.Font.Bold = True
            .Application.Selection.Orientation = 90
            .Application.Selection.Interior.ColorIndex = 15
            .Application.Range("A2").Select
            .Application.ActiveWindow.FreezePanes = True
            .Application.Range("A1").Select
            .Application.Selection.RowHeight = 86
            .Application.Columns("D:D").Select
            .Application.Selection.NumberFormat = "###0.00"
            .Application.Cells.Select
            .Application.Selection.Font.Name = "Arial"
            .Application.Selection.Columns.AutoFit
            .Application.Range("A1").Select
            .Application.ActiveWorkbook.SaveAs FileName:=SavePath
            .Application.ActiveWorkbook.Close
            .Quit
    End With

'Allows user to view and open file
    OpenFileDiag = MsgBox("Feeder review file saved to the the following location:" & vbCrLf & vbCrLf & SavePath & vbCrLf & vbCrLf & "Would you like to view Saved File?", vbYesNo, "View Saved File?")

'Yes selection opens saved formated excel file
    If OpenFileDiag = vbYes Then

        Set XLAppOpenToView = New Excel.Application
            XLAppOpenToView.Visible = True
            XLAppOpenToView.Workbooks.Open SavePath

'No selection unloads excel shell
    ElseIf OpenFileDiag = vbNo Then

            XLapp.Quit
            Set XLapp = Nothing
            Set XLsheet = Nothing

        Exit Sub

    End If
'Unloading of excel shell to prevent multiple open excel instances
    XLapp.Quit
    Set XLapp = Nothing
    Set XLsheet = Nothing

End Sub

你能提供它生成的错误吗? - LThode
2个回答

3

将常量acSpreadsheetTypeExcel9替换为acSpreadsheetTypeExcel12XML


0

尝试将acSpreadsheetTypeExcel9更改为acSpreadsheetTypeExcel12Xml


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接