有同事要将上百个xlsx文件转换为xls,于是写了一个原型。
当然前提是要在装Excel2007的机器上运行才行。
Sub Macro1() ' ' Macro1 Macro ' Dim myFiles Dim i As Long myFiles = Dir("D:/1/*.xlsx") On Error Resume Next Application.ScreenUpdating = True Application.DisplayAlerts = False Do While myFiles <> "" Workbooks.Open Filename:="D:/1/" & myFiles ActiveWorkbook.SaveAs Filename:= _ "D:/1/" & Left(myFiles, Len(myFiles) - 1), FileFormat:=xlExcel8, _ Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _ CreateBackup:=False ActiveWindow.Close myFiles = Dir i = i + 1 DoEvents Loop MsgBox "全部转换完毕,共转换文件 " & i & "个" End Sub
没甚技术含量,文件固定在D:/1目录了,可以进一步改进并增加对子目录的支持。