Save new Workbook as Macro Enabled

Rickinnocal

New Member
Joined
Dec 14, 2010
Messages
31
Office Version
  1. 365
Platform
  1. Windows
Hi, my code creates and saves a new Workbook. Works fine except that it saves it as "Filename.xls" even if I actually put in code to add 'xlsm', and using "FileFormat:=xlOpenXMLWorkbookMacroEnabled"
won't even save the code - it just goes red.
My current code is:

VBA Code:
    sPath = "C:\"
    sFileName = InputBox("Enter file name for new BQS eFile. Recommend Ship Name / Port / BQS eFile")
    oFileName = ActiveWorkbook.Name
    
    'set the sheet to be copied
    Set wsCopy = ThisWorkbook.Worksheets("Prelim (FO)")
    Set wb = Workbooks.Add
    wb.SaveAs Filename:=(sFileName) FileFormat:=xlOpenXMLWorkbookMacroEnabled
    Set wsPaste = wb.Sheets(1)

With the FileFormat:=xlOpenXMLWorkbookMacroEnabled commented out it runs fine saving the file with the name entered into the InputBox, and using .xls as an extension. I've tried various ways to force xlsm as an extension, or using the variant value of a Macro enabled workbook, but none of them work.

What am I doing wrong, please?
 

Some videos you may like

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
20,052
Office Version
  1. 2016
  2. 2013
  3. 2007
Platform
  1. Windows
Try using, but you may need to extend you sPath as sometimes you can't save to the root directory
VBA Code:
wb.SaveAs Filename:=sPath & sFileName, FileFormat:=52
 

Watch MrExcel Video

Forum statistics

Threads
1,127,822
Messages
5,627,096
Members
416,220
Latest member
Sykotik7S

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
Top