Save new Workbook as Macro Enabled

Rickinnocal

New Member
Joined
Dec 14, 2010
Messages
33
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?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
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
 
Upvote 0

Forum statistics

Threads
1,214,943
Messages
6,122,380
Members
449,080
Latest member
Armadillos

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