How to automate converting Excel xls files to Excel xml format?

后端 未结 6 1764
渐次进展
渐次进展 2020-12-19 13:05

I have about 200 Excel files that are in standard Excel 2003 format.

I need them all to be saved as Excel xml - basically the same as opening each file and choosing

6条回答
  •  北海茫月
    2020-12-19 13:31

    Here is a routine that will convert all files in a single directory that have a .xls extension.

    It takes a straight forward approach. Any VBA code in a workbook is stripped out, the workbook is not saved with a .xlsm extension. Any incompatability warning are not dislayed, instead the changes are automatically accepted.

    Sub Convert_xls_Files()
    
    Dim strFile As String
    Dim strPath As String
    
        With Application
            .EnableEvents = False
            .DisplayAlerts = False
            .ScreenUpdating = False
        End With
    'Turn off events, alerts & screen updating
    
            strPath = "C:\temp\excel\"
            strFile = Dir(strPath & "*.xls")
    'Change the path as required
    
        Do While strFile <> ""
            Workbooks.Open (strPath & strFile)
            strFile = Mid(strFile, 1, Len(strFile) - 4) & ".xlsx"
            ActiveWorkbook.SaveAs Filename:=strPath & strFile, FileFormat:=xlOpenXMLWorkbook
            ActiveWorkbook.Close True
            strFile = Dir
        Loop
    'Opens the Workbook, set the file name, save in new format and close workbook
    
        With Application
            .EnableEvents = True
            .DisplayAlerts = True
            .ScreenUpdating = True
        End With
    'Turn on events, alerts & screen updating
    
    End Sub
    

提交回复
热议问题