我编写了这段代码来将一堆 .xlsx 工作簿批量转换为 .xls(我有很多最终用户使用 2003)。它可以完成这项工作,但速度很慢,我在 20 个工作簿上进行了测试,每个工作簿大小只有 30 kb,本地执行需要 9.78 秒。通过我的 sharepoint 服务器,这需要 262 秒,但我相信 sharepoint 的速度非常慢是另一个问题。
代码
Option Explicit
Sub Convert_to972003()
Dim orgwb As Workbook
Dim mypath As String, strfilename As String
Dim nname As String
'--> Error Handling
On Error GoTo WhatHappened
'--> Disable Alerts
With Application
.DisplayAlerts = False
.ScreenUpdating = False
End With
'--> Specify location of workbooks
mypath = "C:\xxx"
strfilename = Dir(mypath & "\*.xlsx", vbNormal)
'--> Check the specified folder contains files
If Len(strfilename) = 0 Then Exit Sub
'--> Start Loop, end when last file reached
Do Until strfilename = ""
'--> Open a workbook
Set orgwb = Application.Workbooks.Open _
(mypath & "\" & strfilename)
'--> Create new Filename, Save in new File Format and Close
nname = Replace(strfilename, ".xlsx", ".xls")
orgwb.SaveAs mypath & "\" & nname, FileFormat:=xlExcel8
orgwb.Close
strfilename = Dir()
Loop
'--> Enable Alerts
With Application
.DisplayAlerts = True
.ScreenUpdating = True
End With
Exit Sub
WhatHappened: MsgBox Err.Description
End Sub
问题
有没有比循环文件夹/打开/保存/关闭更快的方法来转换文件格式?