美文网首页
excel操作 xls批量转excel的vba代码及集成程序工具

excel操作 xls批量转excel的vba代码及集成程序工具

作者: DreamerDK | 来源:发表于2021-05-08 19:38 被阅读0次

今天做多张excel文件数据合并的工作,发现2016版的excel在读取xls文件时无法获取其中的数据。
所以搜索了一番如何进行批量转换。
在此感谢提供的代码的博客:
使用VBA批量转换Excel格式,由.xls转换成.xlsx - 贾树丙 - 博客园 (cnblogs.com)

其文中提供的转换文件的度盘链接已经失效,但代码尚在,所以我又根据其代码重新制作了一份转换工具。
为方便大众使用,我用其代码打包了一份文件进行上传,并且在其中附带了详细的使用说明,让小白也会用。

文件地址:xls批量转xlsx
预览图:

image.png

参考代码:

Sub xls2xlsx()
Dim FilePath, MyFile, iPath, Name, OutPath As String
iPath = ThisWorkbook.Path
OutPath = Dir(iPath & "\xlsx", vbDirectory)
If OutPath = "" Then
    MkDir (iPath & "\xlsx")
End If
MyFile = Dir(iPath & "\*.xls")

If MyFile <> "" Then
Do
    On Error Resume Next
    If MyFile = ThisWorkbook.Name Then MyFile = Dir
    Workbooks.Open (iPath & "\" & MyFile)
    MyFile = Replace(MyFile, ".xls", ".xlsx")
    Name = "\" & MyFile
    FilePath = iPath & "\xlsx" & Name
    Application.ScreenUpdating = False
    ActiveWorkbook.SaveAs Filename:=FilePath, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
    Workbooks(MyFile).Close True
    Application.ScreenUpdating = True
    MyFile = Dir
Loop While MyFile <> ""
End If
End Sub

相关文章

网友评论

      本文标题:excel操作 xls批量转excel的vba代码及集成程序工具

      本文链接:https://www.haomeiwen.com/subject/rhcpdltx.html