VBA SaveAs FileFormat Variable

Chris Macro

Well-known Member
Joined
Nov 2, 2011
Messages
1,345
Office Version
  1. 365
Platform
  1. Windows
I am trying to make a File SaveAs macro that can save in different formats.

This Works:
Code:
ActiveWorkbook.SaveAs Filename:="C:\Users\Chris\Desktop\Book1.xlsx", _
        FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

This Doesn't Work:

Code:
FileFormat = "xlOpenXMLWorkbook"  
        ActiveWorkbook.SaveAs Filename:="C:\Users\Chris\Desktop\Book1.xlsx", _
        FileFormat:=FileFormat, CreateBackup:=False

I'm guessing its because I am setting my FileFormat variable as a string but I am not sure how else to go about making this code variable.

When I try the following code, I get an error stating that an object is required

Code:
Set FileFormat = xlOpenXMLWorkbook
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Here are some file format enumerations. You can simply use the number (as in FileFormat:=##) or you can use the bold text (as in xlOpenXMLWorkbook).

50 = xlExcel12 (Excel binary formatted workbook, with or without macros, .xlsb)
51 = xlOpenXMLWorkbook (macro-free Excel workbook, .xlsx)
52 = xlOpenXMLWorkbookMacroEnabled(Excel workbook with or without macros, .xlsm)
56 = xlExcel8 (Excel 97 through Excel 2003 formatted files .xls)

<colgroup><col style="width:48pt" width="64"> </colgroup><tbody>
</tbody>
 
Upvote 0
Awesome! I didn't think to use the enumerations. Thanks Joe!
 
Upvote 0

Forum statistics

Threads
1,216,171
Messages
6,129,284
Members
449,498
Latest member
Lee_ray

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top