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

今天做多张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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容