0

I have a macro that open all the .xls files in a folder then run a macro to do something to that files, saves and closes them as .xls. My purpose is to save the files but as .xlsx files. I've allready tryed use FileFormatNum = 51, FileFormat = 51 but none of them worked.

If someone has a better approach i appreciate the help.

Sub OpenSave()
Dim myfiles, wb As Workbook, ws As Worksheet
myfiles = Dir(ThisWorkbook.Path & "\*.xls")
Do While Len(myfiles) <> 0
Debug.Print myfiles
Set wb = Workbooks.Open(ThisWorkbook.Path & "\" & myfiles)
   ' Do your stuff here (edit, copy, sort etc...)
Call a Macro
If wb.Name <> ThisWorkbook.Name Then
ActiveWorkbook.Close SaveChanges:=True
Set wb = Nothing
   myfiles = Dir
   End If

Loop End Sub

The macro has adapted from some code i see in a site.

Car
  • 13
  • 7
  • You're opening `.xls` files, but then just using `SaveChanges:=True`, which wouldn't change the file-type...You probably want `ActiveWorkbook.SaveAs ...`? – BruceWayne Feb 25 '19 at 22:31
  • Hi BruceWayne. I want to save the workbook as .xlsx and close it. i try activeworkbook.saveas FileFormat = 51 but it does not work. I dont dominate vba very well. – Car Feb 25 '19 at 23:22
  • does [this thread](https://stackoverflow.com/questions/37570620/struggling-to-save-as-xlsx-file-in-vba) help? – BruceWayne Feb 26 '19 at 00:52
  • Hi, Sorry for my late response but i was sick with flew. that thread does not help because opens the window where you can choose where you want to save the file. My purpose is to save the file automatically. – Car Mar 03 '19 at 21:21

0 Answers0