gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 03:24:50 25 4
gpt4 key购买 nike

我正在处理一个最初编码为输出 .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

最佳答案

将常量 acSpreadsheetTypeExcel9 替换为 acSpreadsheetTypeExcel12XML

关于excel - VBA:从 .xls 切换到 .xlsx 文件格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48082101/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com