我有数百个需要转换为XLSX的XLS文件。
我发现这个旧帖子具有相同的标题,并且提供的代码将文件转换为XLSX但会破坏它们。
我的理解是,此代码使用正确的xlsx扩展名重命名文件,但不更改文件格式。
我的印象是我需要制作文件格式FileFormat:= 51
我尝试在名称中添加“,FileFormat:= 51”,但这似乎不起作用。
有关如何将FileFormat更改为51的任何建议?
谢谢
爱你们
Sub ChangeFileFormat_V1()
Dim strCurrentFileExt As String
Dim strNewFileExt As String
Dim objFSO As Object
Dim objFolder As Object
Dim objFile As File 'Object
Dim xlFile As Workbook
Dim strNewName As String
Dim strFolderPath As String
strCurrentFileExt = ".xls"
strNewFileExt = ".xlsx"
strFolderPath = "C:\Users\Scorpio\Desktop\New folder"
If Right(strFolderPath, 1) <> "\" Then
strFolderPath = strFolderPath & "\"
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.getfolder(strFolderPath)
For Each objFile In objFolder.Files
strNewName = objFile.Name
If Right(strNewName, Len(strCurrentFileExt)) = strCurrentFileExt Then
strNewName = Replace(strNewName, strCurrentFileExt, strNewFileExt)
Application.DisplayAlerts = False
objFile.Name = strNewName
Application.DisplayAlerts = True
End If
Next objFile
``ClearMemory:
strCurrentFileExt = vbNullString
strNewFileExt = vbNullString
Set objFSO = Nothing
Set objFolder = Nothing
Set objFile = Nothing
Set xlFile = Nothing
strNewName = vbNullString
strFolderPath = vbNullString
End Sub
就像我在评论中提到的那样,你不能只是改变扩展并希望它能够工作。你应该打开文件并为每一个做一个qazxsw poi。
这是你在尝试什么? (未测试)
.SaveAs NewFilename,Fileformat