vba html 转化为 xlsx,Excel VBA将一个目录下的所有xls文件批量转换为xlsx文件

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值