单个xls格式的Excel转换成xlsx格式,相信大家都会,打开文件后选择菜单[文件]→[另存为],将弹出保存窗口的保存类型改为"Excel工作簿(*.xlsx),然后点击保存即可.
那么如果有很多xls格式Excel要做转换呢,当然是批量操作了,这就需要使用VBA代码
'***********访问当前文件夹下所有子文件夹及文件, Dim iFile(1 To 100000) As String Dim count As Integer Sub xls2xlsx() iPath = ThisWorkbook.Path On Error Resume Next count = 0 zdir iPath For i = 1 To count If iFile(i) Like "*.xls" And iFile(i) <> ThisWorkbook.FullName Then MyFile = iFile(i) FilePath = Replace(MyFile, ".xls", ".xlsx") If Dir(FilePath, 16) = Empty Then Set WBookOther = Workbooks.Open(MyFile) Application.ScreenUpdating = False ActiveWorkbook.SaveAs Filename:=FilePath, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False WBookOther.Close SaveChanges:=False '解决不能close 文件问题 Application.ScreenUpdating = True End If End If Next End Sub Sub zdir(p) '访问当前文件夹下所有子文件夹及文件 Set fs = CreateObject("scripting.filesystemobject") For Each f In fs.GetFolder(p).Files If f <> ThisWorkbook.FullName Then count = count + 1: iFile(count) = f Next For Each m In fs.GetFolder(p).SubFolders zdir m Next End Sub
具体操作请看动图
文章评论