一段VBA代码将xls转换为xlsx文件

 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





评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值