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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
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).

[TABLE="width: 64"]
<colgroup><col style="width:48pt" width="64"> </colgroup><tbody>[TR]
[TD="class: xl65, width: 64"]50 = xlExcel12 (Excel binary formatted workbook, with or without macros, .xlsb)
[/TD]
[/TR]
[TR]
[TD="class: xl65"]51 = xlOpenXMLWorkbook (macro-free Excel workbook, .xlsx)
[/TD]
[/TR]
[TR]
[TD="class: xl65"]52 = xlOpenXMLWorkbookMacroEnabled(Excel workbook with or without macros, .xlsm)
[/TD]
[/TR]
[TR]
[TD="class: xl65"]56 = xlExcel8 (Excel 97 through Excel 2003 formatted files .xls)
[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Awesome! I didn't think to use the enumerations. Thanks Joe!
 
Upvote 0

Forum statistics

Threads
1,223,652
Messages
6,173,606
Members
452,522
Latest member
saeedfiroozei

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