Create a new workbook with no Macros

ziadh15

New Member
Joined
May 13, 2016
Messages
33
Hello

I have finished writing my code.
After hitting a command button, it will select all visible sheets except two that I specified; and will create a new workbook with those selected sheets.

Now, in that new workbook, when I try to save it; I get an error saying:
" The following features cannot be saved in macro-free workbooks: To save a file with these features, click No and then choose a macro -enabled file type in the File Type List. To continue saving as a macro free workbook click yes"

1) If I click "yes" I get an another error " Errors were detected while saving the file. Microsoft Excel may able to save the file be removing some features. To make repairs click continue. To cancel click cancel"

2) If I click "No", It will force me to chose a file type. After trial and error, I found out that "Excel 97-2003.xls" is the type that lets it save.

My question; what is a workaround to avoid all this mess. I just want the user to be able to save it right away.
Maybe force the VBA to create the new workbook in that specific file type? Or maybe create the new workbook with no Macros?

Appreciate your help
Thanks

Code:
Private Sub CommandButton1_Click()
 


Dim ws As Worksheet
Dim wkb As Workbook
Set wkb = ActiveWorkbook


For Each ws In Sheets
If ws.Name = "Start" Then ws.Visible = False
If ws.Name = "Revision Log" Then ws.Visible = False
If ws.Visible Then ws.Select (False)
Next

ActiveWorkbook.Sheets.Copy

wkb.Close False

End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
check the sheets and see if there is code on them. On the original workbook, right click the tabs and VIEW CODE. Is there code there?
 
Upvote 0
Hmm... strange You could save the new workbooks as macro-enabled and then it wouldn't complain, though there is nothing obvious that indicates your new sheets have macros...UNLESS you are using a function? UDF or something?
 
Upvote 0
When it creates the new workbook, I noticed that my main sheet is inside that workbook but hidden.
It doesn't include any code except the following

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

End Sub

Could that be the problem?

Anyway I force the new excel workbook to open in a specific template that will allow user to save with no warning messages?
 
Upvote 0

Forum statistics

Threads
1,215,619
Messages
6,125,873
Members
449,267
Latest member
ajaykosuri

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