Excel 执行时间慢。从批处理.xlsx到.xls转换
我写这段代码是为了将一堆.xlsx工作簿批量转换为.xls(我有很多最终用户使用2003)。它完成了这项工作,但速度非常慢,我在20本工作簿上测试了这个功能,每本只有大约30KB大小,在本地执行需要9.78秒。通过我的sharepoint服务器,这花费了262秒,但我相信sharepoint速度极慢是另一个问题 代码Excel 执行时间慢。从批处理.xlsx到.xls转换,excel,execution-time,vba,Excel,Execution Time,Vba,我写这段代码是为了将一堆.xlsx工作簿批量转换为.xls(我有很多最终用户使用2003)。它完成了这项工作,但速度非常慢,我在20本工作簿上测试了这个功能,每本只有大约30KB大小,在本地执行需要9.78秒。通过我的sharepoint服务器,这花费了262秒,但我相信sharepoint速度极慢是另一个问题 代码 Option Explicit Sub Convert_to972003() Dim orgwb As Workbook Dim mypath As String,
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
问题
转换文件格式是否有比在文件夹中循环/打开/保存/关闭更快的方法?如果这仍然相关。当我遇到类似问题时,我最终得到了几乎相同的代码,但帮助我加快速度的是禁用,即:
在适当的部分。如果您有由各种Excel事件(如打开或关闭工作簿等)触发的任何其他加载项或宏,这将特别有用。使您无需转换为True,但这将使我的所有最终用户无需安装它,而有些用户可能无法安装它。.您的xlsx文件是格式文件还是纯数据?文件我目前正在应用它来获得普通数据。为什么不使用OLEDB将xlsx文件转换为CSV呢?转换将在眨眼之间发生,文件可以在Excel 2003中读取是的,这有助于加快一点速度,但我试图找到一种不同的方法,我真的认为这是不可能的。
Application.EnableEvents = False
...
Application.EnableEvents = True