excel VBA将一个目录下的所有xls文件批量转换为xlsx文件

时间:2022-08-19 04:46:05 

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 VBA将一个目录下的所有xls文件批量转换为xlsx文件的下载地址:


     

标签:excel,VBA,将,一个,目,录下,的,所有,xls,文件
0
投稿

猜你喜欢

  • Excel中表格添加序号和自动排序的操作方法

    2023-03-30 13:02:11
  • 怎么在word上制作工作简报?word上制作工作简报的方法

    2023-01-09 19:04:41
  • 不花1分钱,112套组织架构word模板,免费送你

    2023-11-09 09:04:36
  • 如何在Excel中制作条形码

    2022-06-18 20:00:36
  • excel 如何复制公式到相邻单元格

    2022-11-19 22:57:24
  • 利用Excel函数进行多条件求和

    2023-01-24 15:22:27
  • win10怎么关闭防火墙提示打游戏?win10关闭防火墙提示打游戏教程

    2023-11-08 13:12:32
  • excel表格怎样将经纬度转换

    2022-07-26 16:10:12
  • excel数据表怎么导入到数据库

    2023-03-23 13:13:16
  • excel如何制作折线图

    2022-09-11 22:04:59
  • Excel2019函数MAXIFS怎么使用?Excel2019函数MAXIFS使用教程

    2022-10-09 16:17:18
  • word中多次绘制直线,每次都要点击插入形状,很烦人!

    2022-10-01 20:32:09
  • 利用word如何使彩色照片快速变为黑白照片?

    2023-11-24 14:43:36
  • iOS 14.5正式版值得第一时间更新吗?iOS 14.5正式版更新建议

    2023-11-02 20:10:27
  • Win10总弹出提示你的电脑遇到问题需要重新启动

    2023-12-14 07:31:26
  • excel表格乘法公式怎么输入

    2023-06-10 06:59:23
  • word论文排版流程

    2022-11-24 08:23:33
  • word怎么画二叉树?

    2023-01-28 04:57:54
  • word中如何制作简历

    2023-09-07 22:27:56
  • Excel 如何添加涨/跌柱线的详细步骤

    2023-08-05 15:58:32
  • asp之家 电脑教程 m.aspxhome.com