Before Save Event

mysterious-dr-x

Board Regular
Joined
Jul 29, 2011
Messages
51
It is in ThisWorkbook as it should be, however it doesn't work, what have I done wrong....again....?

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Call Remove_Duplicates
    Call ReOrder
End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
It is possible that your code is not working because 'Events' are disabled. In the VBA window, ensure the Immediate Window is visible (View|Immediate Window) and then on a new line in the Immediate Window, type

Application.EnableEvents=True and press Enter

Now go back to your workbook and try saving again.
 
Upvote 0
Have you enabled macros? Set a breakpoint in the first line of the code?
 
Upvote 0
Have you enabled macros? Set a breakpoint in the first line of the code?

Yes, & have just tried, no luck.

It seems to be dissatisfied with this part;

Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
 
Upvote 0
In what way is this dissatisfaction made manifest?
 
Upvote 0
Have you enabled macros? Set a breakpoint in the first line of the code?

Yes, & have just tried, no luck.
Is that a Yes to both shg's questions? If you add the blue line of code and save the workbook do you get the message box?
Rich (BB code):
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    MsgBox "BeforeSave code has fired"
    Call Remove_Duplicates
    Call ReOrder
End Sub
 
Upvote 0
No, I do not
OK, not trying to be rude here but just thinking aloud. You say that you have checked and..
- 'Events' are not disabled
- Macros are enabled
- Workbook_BeforeSave code is in the ThisWorkbook module
- Workbook_BeforeSave event is not firing

What explanations are there?
a) Events are disabled
b) Macros are not enabled
c) The Workbook_BeforeSave code is in the wrong ThisWorkbook module.
d) (Other possibilities?)
 
Upvote 0
What if you take a fresh workbook and save it. Then, with no other code, put this in its ThisWorkbook module then try to save the workbook again. Do you get the message box?
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    MsgBox "BeforeSave code has fired"
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

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