help! can't get the code to save in the workbook

whiteghost

Well-known Member
Joined
Nov 22, 2002
Messages
500
Hi,

PCC gave me the code for disabling the "saveas"

private sub Workbook_BeforeSave(ByVal SaveAsUl As Boolean, Cancel As Boolean)
cancel = SaveAsUl
end sub

This works fine until the file is saved and closed. On reopening the file, this code has not been saved.

what am I doing wrong?
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
yes. The code will not save regardless of what I try. It works until the workbook is closed then re-opened.
 
Upvote 0
yes. The code will not save regardless of what I try. It works until the workbook is closed then re-opened.
 
Upvote 0
Here's a goofy question, but it has to be asked...are you sure you're putting the code in the correct ThisWorkbook?
 
Upvote 0
Oh, well, your code says, "Before Save, Cancel." So actually, you can't save the workbook with that code in there because that code cancels the save.
 
Upvote 0
Yes. Put a Breakpoint in the code. Then try saving. It should stop when it hits the breakpoint. Now, hit save as. The code should be saved for the next time you open it! :D
 
Upvote 0
ok forgive me if I'm being stupid, but you mean put the breakpoint at "cancel=SaveAsUl"?

tried that and it still does not save
 
Upvote 0

Forum statistics

Threads
1,221,706
Messages
6,161,406
Members
451,702
Latest member
Kc3475

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