我在这里找到了这个:
http://enholm.net/index.php/blog/vba-code-to-transfer-excel-2007-xlsx-books-to-2003-xls-format/
它在目录中搜索xlsx文件并将它们更改为xls文件
我认为尽管可以将其更改为查找xlsm文件并将它们也更改为xls文件。
当我运行它时,我得到:
Run-Time error '9' Subscript out of range
Debug
Sheets("List").Cells(r, 1) = Coll_Docs(i)
is highlighted in yellow
我对 vba 的了解还不够,无法弄清楚什么是行不通的。谢谢
Sub SearchAndChange()
Dim Coll_Docs As New Collection
Dim Search_path, Search_Filter, Search_Fullname As String
Dim DocName As String
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim i As Long
Search_path = ThisWorkbook.Path & "\360 Compiled Repository\May_2013"
Search_Filter = "*.xlsx"
Set Coll_Docs = Nothing
DocName = dir(Search_path & "\" & Search_Filter)
Do Until DocName = ""
Coll_Docs.Add Item:=DocName
DocName = dir
Loop
r = 1
For i = Coll_Docs.Count To 1 Step -1
Search_Fullname = Search_path & "\" & Coll_Docs(i)
Sheets("List").Cells(r, 1) = Coll_Docs(i)
Call changeFormats(Search_path, Coll_Docs(i))
r = r + 1
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
'**************************************************************
'* Changes format from excel 2007 to 2003
'***************************************************************
Sub changeFormats(ByVal dir As String, ByVal fileName As String)
Workbooks.Open fileName:=dir & fileName
ActiveWorkbook.SaveAs fileName:=dir & Replace(fileName, "xlsx", "xls"), FileFormat:=xlExcel8
ActiveWindow.Close
End Sub