I am trying to convert xlsx files into xls using vba macro or python code.So far,I could get some help on converting files in a single folder using the below code:
Sub ProcessFiles()
Dim Filename, Pathname, saveFileName As String
Dim wb As Workbook
Dim initialDisplayAlerts As Boolean
Pathname = ""
Filename = Dir(Pathname & "*.xlsx")
initialDisplayAlerts = Application.DisplayAlerts
Application.DisplayAlerts = False
Do While Filename <> ""
Set wb = Workbooks.Open(Filename:=Pathname & Filename, _
UpdateLinks:=False)
wb.CheckCompatibility = False
saveFileName = Replace(Filename, ".xlsx", ".xls")
wb.SaveAs Filename:=Pathname & saveFileName, _
FileFormat:=xlExcel8, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
wb.Close SaveChanges:=False
Filename = Dir()
Loop
Application.DisplayAlerts = initialDisplayAlerts
End Sub
I am now trying to generalize this to all subfolders inside the given folder.
On a larger note,I am trying to build a macro which does the following:
- Run this in batch mode where the parent folder is constant.
- Process the code at background and put all the converted files in respective folders.
For example, Max is my main folder inside which there may be Med ,Det,Vis,Liv sub-folders.Inside each subfolder,there will be thousands of xlsx files which need to be converted and placed at the same location where the parent file is stored.
Please help.
Thanks, Maddy