Run-time error '1004': VB Projects and XML sheets cannot be saved in a macro-free workbook.

KJayy

New Member
Joined
Jul 22, 2015
Messages
2
Hi. Thanks in advance all. I'm running Excel 2013 and I've written a macro to save a .xlsm to .xlsx, and I have a few questions about this. PROBLEM 1: When I run my save as code, I get a dialog which reads, "The following features cannot be saved in macro-free workbooks: VB Project. To save a file with these features, click No, and then choose a macro-enabled file type in the File Type list." If I press Yes the files saves as a .xlsx. However, if I press No to this dialog I get, "Run-time error '1004': VB Projects and XML sheets cannot be saved in a macro-free workbook." This dialog has two options - End or Debug. If I press Debug it takes me to this line of code:
Code:
ActiveWorkbook.SaveAs Filename:=fileSaveName, FileFormat:=51
The preceeding code is as follows:
Code:
  NewFilename = Trim(GetCellString("Customer Database", "B" & CustomerID) & "_" & NewInvoiceNum & ".xlsx")    fileSaveName = Application.GetSaveAsFilename(InitialFileName:=NewFilename, filefilter:="Text Files (*.xlsx), *.xlsx")            If fileSaveName <> False Then                               ' Save the new .xlsx and make the Customer Invoice worksheet current                               ActiveWorkbook.SaveAs Filename:=fileSaveName, FileFormat:=51
QUESTION 1: How do I capture the runtime error 1004 so I can handle error appropriately without presenting users with End or Debug? QUESTION 2: How do I get this dialog NOT to appear? Can I do this programmatically? PROBLEM 2: When the file is saved as a .xlsx, even though I go into the VB editor and even though I do not see my macro code, the code is still executable in spite of the file extension being .xlsx. Why is this? When I save certain spreadsheets, I need to save them so the macros are removed and truly gone and can never be run again. How can I do this? Thanks. KJ
 
Last edited:

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Sorry about the formatting folks. For some reason the post would not retain my original formatting.

I found the answer to problem number one in this post - http://www.mrexcel.com/forum/excel-questions/498977-macro-save-macro-free-display.html. That was to add these lines above and below (respectively) the
ActiveWorkbook.SaveAs Filename:=fileSaveName, FileFormat:=51 line of code:

Code:
Application.DisplayAlerts = False[COLOR=Blue][COLOR=Blue]
Application.DisplayAlerts = True[/COLOR][/COLOR]

However, problem #2 remains. Any help you have with this one would be greatly appreciated.

Thanks.
KJ
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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