Confira o Gerenciador de planejamento de migração do Office.
The toolkit also contains the Office File Converter (OFC), which enables bulk document conversions from binary to OpenXML formats. (Technet)
Link para download
Eu tenho que trabalhar com um aplicativo antigo que só pode exportar arquivos XLS e escrevo programas em .Net usando a biblioteca EPPlus que é capaz apenas de ler arquivos XLSX.
Qual é a maneira mais fácil de converter em lotes de XLS para XLSX?
Confira o Gerenciador de planejamento de migração do Office.
The toolkit also contains the Office File Converter (OFC), which enables bulk document conversions from binary to OpenXML formats. (Technet)
Link para download
Eu recomendo usar uma macro para processar os arquivos dentro de uma pasta para convertê-los de xls para xlsx. Este código pressupõe que os arquivos estão todos localizados dentro de uma pasta e que todos os arquivos xls precisam ser convertidos, mas se você quiser selecionar arquivos individuais, este código pode ser atualizado.
Esse código precisa ser executado em uma pasta de trabalho do Excel 2007 ou do Excel 2010.
Option Explicit
' Convert all xls files in selected folder to xlsx
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
strConversionPath = .SelectedItems(1)
End With
Set FSO = New Scripting.FileSystemObject
' Check if the folder exists
If FSO.FolderExists(strConversionPath) Then
Set fFolder = FSO.GetFolder(strConversionPath)
' Loop through files, find the .xls files
For Each fFile In fFolder.Files
If Right(fFile.Name, 4) = ".xls" Or Right(fFile.Name, 4) = ".XLS" Then
Application.DisplayAlerts = False
Set wkbConvert = Workbooks.Open(fFile.Path)
' Save as XML workbook - if file contains macros change FileFormat:=52
wkbConvert.SaveAs FSO.BuildPath(fFile.ParentFolder, Left(fFile.Name, Len(fFile.Name) - 4)) & ".xlsx", FileFormat:=51
wkbConvert.Close SaveChanges:=False
' Delete original file
fFile.Delete Force:=True
Application.DisplayAlerts = True
End If
Next fFile
End If
End Sub
Se os arquivos que você está convertendo contiverem macros, será necessário atualizar o 'FileFormat: = 51' para ler 'FileFormat: = 52'. Ou, se você não precisar codificar a macro nos arquivos convertidos, poderá deixá-lo em paz e removerá as macros quando elas forem convertidas para o formato xlsx.
Sub SaveAllAsXLSX()
Dim strFilename As String
Dim strDocName As String
Dim strPath As String
Dim wbk As Workbook
Dim fDialog As FileDialog
Dim intPos As Integer
Dim strPassword As String
Dim strWritePassword As String
Dim varA As String
Dim varB As String
Dim colFiles As New Collection
Dim vFile As Variant
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select folder and click OK"
.AllowMultiSelect = True
.InitialView = msoFileDialogViewList
If .Show -1 Then
MsgBox "Cancelled By User", , "List Folder Contents"
Exit Sub
End If
strPath = fDialog.SelectedItems.Item(1)
If Right(strPath, 1) "\" Then strPath = strPath + "\"
End With
If Left(strPath, 1) = Chr(34) Then
strPath = Mid(strPath, 2, Len(strPath) - 2)
End If
Set obj = CreateObject("Scripting.FileSystemObject")
RecursiveDir colFiles, strPath, "*.xls", True
For Each vFile In colFiles
Debug.Print vFile
strFilename = vFile
varA = Right(strFilename, 3)
If (varA = "xls" Or varA = "XLSX") Then
Set wbk = Workbooks.Open(Filename:=strFilename)
If wbk.HasVBProject Then
wbk.SaveAs Filename:=strFilename & "m", FileFormat:=xlOpenXMLWorkbookMacroEnabled
Else
wbk.SaveAs Filename:=strFilename & "x", FileFormat:=xlOpenXMLWorkbook
End If
wbk.Close SaveChanges:=False
obj.DeleteFile (strFilename)
End If
Next vFile
End Sub
Public Function RecursiveDir(colFiles As Collection, _
strFolder As String, _
strFileSpec As String, _
bIncludeSubfolders As Boolean)
Dim strTemp As String
Dim colFolders As New Collection
Dim vFolderName As Variant
'Add files in strFolder matching strFileSpec to colFiles
strFolder = TrailingSlash(strFolder)
strTemp = Dir(strFolder & strFileSpec)
Do While strTemp vbNullString
colFiles.Add strFolder & strTemp
strTemp = Dir
Loop
If bIncludeSubfolders Then
'Fill colFolders with list of subdirectories of strFolder
strTemp = Dir(strFolder, vbDirectory)
Do While strTemp vbNullString
If (strTemp ".") And (strTemp "..") Then
If (GetAttr(strFolder & strTemp) And vbDirectory) 0 Then
colFolders.Add strTemp
End If
End If
strTemp = Dir
Loop
'Call RecursiveDir for each subfolder in colFolders
For Each vFolderName In colFolders
Call RecursiveDir(colFiles, strFolder & vFolderName, strFileSpec, True)
Next vFolderName
End If
End Function
Public Function TrailingSlash(strFolder As String) As String
If Len(strFolder) > 0 Then
If Right(strFolder, 1) = "\" Then
TrailingSlash = strFolder
Else
TrailingSlash = strFolder & "\"
End If
End If
End Function
Se você tiver o MsOffice instalado, essa ferramenta pode valer um download para uma solução rápida.
Quando você seleciona uma pasta para ver os arquivos xls convertidos, certifique-se de selecionar a opção de ferramenta de conversão que usa o MS Office para a conversão, não o seu próprio conversor.
Se você usar o seu próprio conversor, você perderá cores nas células e a folha solta parece sair. Se você usar o MsOffice como o conversor parece funcionar bem. Boa ferramenta para uma solução rápida.
Então escrevi um VBScript simples para converter arquivos .xls em .xlsx de maneira silenciosa.
./convert-xls-xlsx.vbs {path to folder containing .xls files}
convert-xls-xlsx.vbs:
Set args = WScript.Arguments
strPath = args(0)
strPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(strPath)
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = False
objExcel.DisplayAlerts = False
Set objFso = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFso.GetFolder(strPath)
For Each objFile In objFolder.Files
fileName = objFile.Path
If (objFso.GetExtensionName(objFile.Path) = "xls") Then
Set objWorkbook = objExcel.Workbooks.Open(fileName)
saveFileName = Replace(fileName,".xls",".xlsx")
objWorkbook.SaveAs saveFileName,51
objWorkbook.Close()
objExcel.Application.DisplayAlerts = True
End If
Next
MsgBox "Finished conversion"
NOTA: Procure espaços no caminho da pasta, se o seu caminho tiver um espaço no meio, coloque o caminho entre aspas.