PDA

View Full Version : [SOLVED:] VBA Code to change file format .xlm to .xlxs



foxyginger
06-09-2017, 03:13 PM
I'm working on a project that requires MACROS, but is also required to be saved as *.xlxs to run in the database I'm using. Is there a way to build a MACRO to achieve this? I realize that .xls and .xlsx both are created to protect against MACROS, so I understand if this is not realistic.

Paul_Hossler
06-09-2017, 03:55 PM
I'd write a macro (which has to be in the XLSM) that writes a COPY of the XLSM workbook (or just the desired worksheets) to a new workbook which is then saved as a XLSX

foxyginger
06-09-2017, 04:14 PM
That's a great way to think about it!

This is what I found on another forum-- I'll try this just changing my filename format.


Sub SaveAs()

Dim FName As String
Dim FPath As String

FPath = "G:\Exceptions\"
FName = "Exceptions" & Format(Date, "ddmmyy") & ".xls"

Sheets("DataSort").Copy
ThisWorkbook.Sheets("Sheet1").SaveAs Filename:=FPath & "\" & FName

End Sub

Paul_Hossler
06-09-2017, 04:26 PM
1. The [#] icon will insert [ CODE ] ....... [/ CODE ] markers for you to paste the macro between; does some formatting and makes it easier to read

2. You can use the macro recorder to give you something to work with as a starting point




Option Explicit
Sub Macro1()

Sheets("Sheet1").Select
Sheets("Sheet1").Copy
ActiveWorkbook.SaveAs Filename:="C:\Users\USER\Documents\test_09062017.xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close
End Sub

foxyginger
06-09-2017, 05:18 PM
Great, thank you so much!