Sub save_xls_to_xlsx()
Dim folder As FileDialog
Dim f, fdi As FileDialogSelectedItems
Dim i As Integer
Dim file_count As Integer
Dim xls_file As String
Dim xlsx_file As String
Dim wb As Workbook
Set folder = Application.FileDialog(msoFileDialogFolderPicker)
folder.Show
Set fdi = folder.SelectedItems
If fdi.Count = 0 Then
MsgBox "未选择任何文件夹。"
Exit Sub
End If
For Each f In fdi
xls_file = Dir(f & "\*.xls")
file_count = 0
Do
If Right(xls_file, 4) = ".xls" Then
Set wb = Workbooks.Open(f & "\" & xls_file)
Application.ScreenUpdating = False
xlsx_file = f & "\" & xls_file & "x"
ActiveWorkbook.SaveAs Filename:=xlsx_file, FileFormat:=xlWorkbookDefault, CreateBackup:=False
wb.Close savechanges:=False
Kill f & "\" & xls_file '若不想删除原文件,可注释掉本行
file_count = file_count + 1
Application.ScreenUpdating = True
End If
xls_file = Dir
Loop Until xls_file = ""
Next
MsgBox "该文件夹下的xls文件(共" & CStr(file_count) & "个)已全部转换为xlsx文件。"
End Sub
一段VBA代码将xls转换为xlsx文件
最新推荐文章于 2024-09-26 16:07:24 发布