Câu trả lời:
Kiểm tra Trình quản lý kế hoạch di chuyển văn phòng.
Bộ công cụ cũng chứa Trình chuyển đổi tệp Office (OFC), cho phép chuyển đổi tài liệu hàng loạt từ định dạng nhị phân sang định dạng OpenXML. ( Kỹ thuật )
Lưu ý rằng bạn cũng sẽ cần Microsoft Office Compatibility Pack for Word, Excel, and PowerPoint File Formatsđể OFC hoạt động.
Cả hai công cụ dường như không thực sự được hỗ trợ nữa.
Tôi khuyên bạn nên sử dụng macro để xử lý các tệp trong thư mục để chuyển đổi chúng từ xls sang xlsx. Mã này giả định rằng tất cả các tệp nằm trong một thư mục và tất cả các tệp xls cần được chuyển đổi, nhưng nếu bạn muốn chọn các tệp riêng lẻ thì mã này có thể được cập nhật.
Mã này sẽ cần được chạy từ sổ làm việc Excel 2007 trở lên.
Option Explicit
' Convert all xls files in selected folder to xlsx
Public Sub convertXLStoXLSX()
Dim FSO As Scripting.FileSystemObject
Dim strConversionPath As String
Dim fFile As File
Dim fFolder As Folder
Dim wkbConvert As Workbook
' Open dialog and select folder
With Application.FileDialog(msoFileDialogFolderPicker)
.AllowMultiSelect = False
.Show
On Error Resume Next ' Prevent debug mode if user cancels selection
strConversionPath = .SelectedItems(1)
On Error GoTo 0 ' Re-enable default error handling
End With
Set FSO = New Scripting.FileSystemObject
' Check if the folder exists
If FSO.FolderExists(strConversionPath) Then
Set fFolder = FSO.GetFolder(strConversionPath)
' Disable confirmation dialogs (to prevent "unsaved changes" dialog popping up)
' and screen updates (to speed up conversion)
Application.DisplayAlerts = False
Application.ScreenUpdating = False
' Loop through files, find the .xls files
For Each fFile In fFolder.Files
If LCase$(Right(fFile.Name, 4)) = ".xls" Then
' Open temporary workbook
Set wkbConvert = Workbooks.Open(fFile.Path)
' Save as OpenXML workbook - if your .xls files contain macros
' then change to FileFormat:=xlOpenXMLWorkbookMacroEnabled
wkbConvert.SaveAs FSO.BuildPath(fFile.ParentFolder, _
Left(fFile.Name, Len(fFile.Name) - 4)) & ".xlsx", _
FileFormat:=xlOpenXMLWorkbook
wkbConvert.Close SaveChanges:=False
' Delete original file
fFile.Delete Force:=True
End If
Next fFile
' Re-enable confirmation dialogs and screen updates
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End If
End Sub
Lưu ý: Nếu các tệp bạn đang chuyển đổi chứa macro thì bạn cần cập nhật
FileFormat:=xlOpenXMLWorkbookđể đọcFileFormat:=xlOpenXMLWorkbookMacroEnabled. Hoặc nếu bạn không cần mã macro trong các tệp đã chuyển đổi, bạn có thể để nó một mình và nó sẽ xóa các macro khi chuyển đổi nó sang định dạng xlsx.
Sub Save AllAsXLSX ()
Dim strFilename As String
Dim strDocName dưới dạng Chuỗi
Dim strPath dưới dạng chuỗi
Dim wbk Như sách bài tập
Dim fDialog Như FileDialog
Dim intPos là số nguyên
Dim strPassword As String
Dim strWritePassword As String
Dim varA As String
Dim varB dưới dạng chuỗi
Dim colFiles Như bộ sưu tập mới
Dim vFile Như biến thể
Đặt fDialog = Application.FileDialog (msoFileDialogFolderPicker)
Với fDialog
.Title = "Chọn thư mục và nhấp vào OK"
. ALLowMultiSelect = True
.InitialView = msoFileDialogViewList
Nếu. Hiển thị -1 Sau đó
MsgBox "Đã hủy bởi người dùng", "Danh sách nội dung thư mục"
Thoát Sub
Kết thúc nếu
strPath = fDialog.SelectedItems.Item (1)
Nếu phải (strPath, 1) "\" Sau đó strPath = strPath + "\"
Kết thúc với
Nếu còn lại (strPath, 1) = Chr (34) Sau đó
strPath = Mid (strPath, 2, Len (strPath) - 2)
Kết thúc nếu
Đặt obj = CreateObject ("Scripting.FileSystemObject")
RecursiveDir colFiles, strPath, "* .xls", Đúng
Đối với mỗi vFile Trong colFiles
Gỡ lỗi.Print vFile
strFilename = vFile
varA = Right (strFilename, 3)
Nếu (varA = "xls" Hoặc varA = "XLSX") thì
Đặt wbk = Workbooks.Open (Tên tệp: = strFilename)
Nếu wbk.HasVBProject thì
wbk.SaveAs Tên tệp: = strFilename & "m", FileFormat: = xlOpenXMLWorkbookMacroEnabled
Khác
wbk.SaveAs Tên tệp: = strFilename & "x", FileFormat: = xlOpenXMLWorkbook
Kết thúc nếu
wbk. Đóng SaveChanges: = Sai
obj.DeleteFile (strFilename)
Kết thúc nếu
Tiếp theo vFile
Kết thúc phụ
Chức năng công khai RecursiveDir (colFiles As Collection, _
strFolder Như Chuỗi, _
strFileSpec dưới dạng Chuỗi, _
bIncludeSub Folders As Boolean)
Dim strTemp As String
Dim colFolders là bộ sưu tập mới
Dim vFolderName là biến thể
'Thêm tệp trong strFolder khớp strFileSpec vào colFiles
strFolder = TrailingSlash (strFolder)
strTemp = Dir (strFolder & strFileSpec)
Làm trong khi strTemp vbNullString
colFiles.Add strFolder & strTemp
strTemp = Dir
Vòng
Nếu bIncludeSub Folders Then
'Điền vào colFolders với danh sách các thư mục con của strFolder
strTemp = Dir (strFolder, vbDirectory)
Làm trong khi strTemp vbNullString
Nếu (strTemp ".") Và (strTemp "..") Sau đó
Nếu (GetAttr (strFolder & strTemp) và vbDirectory) 0 Sau đó
colFolders. Thêm strTemp
Kết thúc nếu
Kết thúc nếu
strTemp = Dir
Vòng
'Gọi RecursiveDir cho mỗi thư mục con trong colFolders
Đối với mỗi vFolderName trong colFolders
Gọi RecursiveDir (colFiles, strFolder & vFolderName, strFileSpec, True)
Tiếp theo vFolderName
Kết thúc nếu
Chức năng kết thúc
Chức năng công cộng TrailingSlash (strFolder As String) dưới dạng chuỗi
Nếu Len (strFolder)> 0 Sau đó
Nếu phải (strFolder, 1) = "\" Sau đó
TrailingSlash = strFolder
Khác
TrailingSlash = strFolder & "\"
Kết thúc nếu
Kết thúc nếu
Chức năng kết thúc
Nếu bạn đã cài đặt MsOffice, thì công cụ này có thể đáng để tải xuống để khắc phục nhanh.
http://www.softinterface.com/Convert-XLS/Features/Convert-XLS-To-XLSX.htm
Khi bạn chọn thư mục để xem các tệp xls được chuyển đổi, hãy đảm bảo bạn đánh dấu tùy chọn công cụ chuyển đổi sử dụng MS Office để chuyển đổi, chứ không phải trình chuyển đổi của riêng họ.
Nếu bạn sử dụng trình chuyển đổi riêng của họ, bạn sẽ mất màu trong các ô và bảng đơn dường như xuất hiện. Nếu bạn sử dụng MsOffice làm trình chuyển đổi dường như hoạt động tốt. Công cụ tốt để sửa chữa nhanh chóng.
Vì vậy, tôi đã viết một VBScript đơn giản để chuyển đổi các tệp .xls thành .xlsx một cách im lặng.
./convert-xls-xlsx.vbs {đường dẫn đến thư mục chứa tệp .xls}
convert-xls-xlsx.vbs:
Đặt args = WScript.Argument
strPath = args (0)
strPath = CreateObject ("Scripting.FileSystemObject"). GetAbsolutePathName (strPath)
Đặt objExcel = CreateObject ("Excel.Application")
objExcel.Visible = Sai
objExcel.DisplayAlerts = Sai
Đặt objFso = CreateObject ("Scripting.FileSystemObject")
Đặt objFolder = objFso.GetFolder (strPath)
Đối với mỗi objFile Trong objFolder.Files
fileName = objFile.Path
If (objFso.GetExtensionName (objFile.Path) = "xls") Sau đó
Đặt objWorkbook = objExcel.Workbooks.Open (tên tệp)
saveFileName = Thay thế (fileName, ". xls", ". xlsx")
objWorkbook.SaveAs saveFileName, 51
objWorkbook. Đóng ()
objExcel.Application.DisplayAlerts = True
Kết thúc nếu
Kế tiếp
MsgBox "Hoàn tất chuyển đổi"
LƯU Ý: Xem ra khoảng trắng trong đường dẫn thư mục, nếu đường dẫn của bạn có khoảng trắng ở giữa, hãy đặt đường dẫn trong dấu ngoặc kép.