一些选项应该更快.
使用Powershell
(将以下代码保存在记事本中,如xx.ps1,更新源目录并运行)
在隐藏的实例中而不是在当前的实例中自动执行Excel.
电源外壳
借鉴https://superuser.com/questions/875831/using-powershell-is-it-possible-to-convert-an-xlsx-file-to-xls并使用Powershell循环浏览Excel文件并检查电子表格名称存在
$files = Get-ChildItem C:\Temp\*.txt Write "Loading Files..." $Excel = New-Object -ComObject Excel.Application $Excel.visible = $false $Excel.DisplayAlerts = $false ForEach ($file in $files) { $WorkBook = $Excel.Workbooks.Open($file.Fullname) $NewFilepath = $file.Fullname -replace ".{4}$" $NewFilepath = $NewFilepath + ".xls" $Workbook.SaveAs($NewFilepath,56) } Stop-Process -processname EXCEL $Excel.Quit()
自动化Excel
Sub TXTconvertXLS2() Dim objExcel As Excel.Application Dim wb As Workbook Dim strFile As String Dim strDir As String Set objExcel = New Excel.Application With objExcel .Visible = False .DisplayAlerts = False End With 'Directories strDir = "c:\temp\" strFile = Dir(strDir & "*.txt") 'Loop Do While strFile <> "" Set wb = objExcel.Workbooks.Open(strDir & strFile) With wb .SaveAs Replace(wb.FullName, ".txt", ".xls"), 50 .Close False '<-already saved in the line directly above End With Set wb = Nothing strFile = Dir '<- stuffs the next filename into strFile Loop objExcel.DisplayAlerts = False objExcel.Quit Set objExel = Nothing End Sub