Excel xls批量轉換為xlsx
readme:
*本人Excel版本為2021,WPS沒有試驗過
1、在需要轉換的excel所在資料夾中新建一個xlsx的excle
2、開啟新建的Excle,按alt+F11
3、選中開啟左邊當前Excel的Sheet
4、將文尾VBA程式碼貼上進去,點選執行
轉換成功
VBA程式碼:
'***********訪問當前資料夾下所有子資料夾及檔案,
Dim iFile(1 To 100000) As String
Dim count As Integer
Sub xls2xlsx()
iPath = ThisWorkbook.Path
On Error Resume Next
count = 0
zdir iPath
For i = 1 To count
If iFile(i) Like "*.xls" And iFile(i) <> ThisWorkbook.FullName Then
MyFile = iFile(i)
FilePath = Replace(MyFile, ".xls", ".xlsx")
If Dir(FilePath, 16) = Empty Then
Set WBookOther = Workbooks.Open(MyFile)
Application.ScreenUpdating = False
ActiveWorkbook.SaveAs Filename:=FilePath, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
WBookOther.Close SaveChanges:=False '解決不能close 檔案問題
Application.ScreenUpdating = True
End If
End If
Next
End Sub
Sub zdir(p) '訪問當前資料夾下所有子資料夾及檔案
Set fs = CreateObject("scripting.filesystemobject")
For Each f In fs.GetFolder(p).Files
If f <> ThisWorkbook.FullName Then count = count + 1: iFile(count) = f
Next
For Each m In fs.GetFolder(p).SubFolders
zdir m
Next
End Sub