Dưới đây là một thói quen mà sẽ chuyển đổi tất cả các file trong một thư mục có phần mở rộng .xls.
Phương pháp tiếp cận thẳng về phía trước. Bất kỳ mã VBA nào trong sổ làm việc bị loại bỏ, sổ làm việc không được lưu với phần mở rộng .xlsm. Bất kỳ cảnh báo không tương thích nào không bị thay đổi, thay vào đó các thay đổi sẽ tự động được chấp nhận.
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
Nguồn
2008-10-06 23:14:40
Cảm ơn Robert, nó đã làm việc rất tốt. Điều duy nhất tôi thay đổi là FileFormat: = XlFileFormat.xlXMLSpreadsheet (Tôi đang sử dụng Excel 2003) – kristof
Đoạn mã trên có thể được viết bằng php không? – chupinette