您现在的位置是:主页 > 批量快捷 >
excel VBA将一个目录下的所有xls文件批量转换为xlsx文件
发布时间:2023-10-23 05:26:34所属栏目:批量快捷 已帮助人编辑作者:Excel自学教程
Option Explicit
Sub xlsTOxlsx()
Dim strFilePath As String, strFileName As String, strFileType As String
Dim aIndex As Long, arrFileName() As String, strNewName As String
'设置文件扩展名标识文件类型
strFileType = ".xls"
On Error Resume Next
'设置文件夹路径
strFilePath = CreateObject("shell.application").BrowseForFolder(0, "请选择文件夹", 0).self.Path
If Err <> 0 Or InStr(1, strFilePath, "::") > 0 Then
Err = 0
Exit Sub
End If
'开始搜索文件
strFileName = Dir(strFilePath & "*.*")
Do While strFileName <> ""
If LCase(Right(strFileName, Len(strFileType))) = LCase(strFileType) Then
ReDim Preserve arrFileName(aIndex)
arrFileName(aIndex) = strFileName
aIndex = aIndex + 1
'Debug.Print strFileName
End If
strFileName = Dir
DoEvents
Loop
If aIndex = 0 Then Exit Sub
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For aIndex = LBound(arrFileName) To UBound(arrFileName)
strNewName = Mid(arrFileName(aIndex), 1, Len(arrFileName(aIndex)) - Len(strFileType)) & ".xlsx"
Workbooks.Open strFilePath & arrFileName(aIndex)
ActiveWorkbook.SaveAs Filename:=strFilePath & strNewName, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Workbooks(strNewName).Close False '关闭工作簿
Kill strFilePath & arrFileName(aIndex)
DoEvents
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "操作完成,共为您转换了 " & UBound(arrFileName) + 1 & " 个文件。", vbOKOnly, "完成"
End Sub
以上就是excel自学教程为您提供excel VBA将一个目录下的所有xls文件批量转换为xlsx文件的解读,本文章链接: http://www.5enet.cn/Excel_piliang/78328.html 欢迎分享转载,更多相关资讯请前往批量快捷
相关文章
企业IT外包服务
excel 如何快速的找到对应的预提与冲销
Excel中ISEVEN函数的语法和用法
excel如何高亮显示工作表中所有包含公式的单元格
excel图表 基于隔离的兼容
excel if函数的多个条件使用方法
如何利用excel下拉框实现数据条件统计实例教程
excel表格怎么内插竖线
excel vlookup函数的反向查找、模糊查找、多条件查找
excel 如何统计两个日期之间某个数据的数量求和值?
Excel中PROB函数的语法和用法
如何快速在Excel中隔行填充颜色
Excel表格怎么打印在a4纸上
wps表格办公—如何处理每次打开工作簿时弹出的提示框?
如何以最简单方式实现中小企业数据共享协同?
excel FIND函数 实现将短划线号前小于10的数前添加0
扫码关注
- 专注IT行业,10年IT行业经验