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
 
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?)

a) Is there a way to check on this other than Application.EnableEvents=True ?
b) Other macros work, but I did check in security anyway & macros are on.
c) I made sure that this wasn't the case by this being the only workbook open, definitely in the right place.
d) No idea what else it could be.


EDIT: I've just remembered that whilst this was originally a .xlsm, it is now just .xls, might this make a difference to anything?
 
Last edited:
Upvote 0

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
What version of Excel are you using?

Did you try the suggestion in post #10?
 
Upvote 0
How is the Before Save event being called? For example, are you clicking on the save button in the Excel interface, or are you calling it from another VBA procedure?
 
Upvote 0
What version of Excel are you using?

Did you try the suggestion in post #10?

I'm using excel 2007 & I just tried #10, & that worked ok.

How is the Before Save event being called? For example, are you clicking on the save button in the Excel interface, or are you calling it from another VBA procedure?

I have tried both, & both seem to fail the same.
 
Upvote 0
Please can you upload the problematic workbook somewhere so that we can download and see it?
 
Upvote 0
I'm using excel 2007 & I just tried #10, & that worked ok.
Had you saved that file as .xls or .xlsm?

Had you saved that file in the same location as the 'problem' one?

What, exactly, are your settings in ..

Office icon|Excel Options|Trust Center|Trust Center Settings...|Macro Settings

Do you have any locations here?
Office icon|Excel Options|Trust Center|Trust Center Settings...|Trusted Locations

If so, do the Trusted Locations contain the location of either the 'problem' file or the new one you tried re post #10?
 
Upvote 0
Please can you upload the problematic workbook somewhere so that we can download and see it?

I'd rather not if I can help it, although I know this may slow the fixing process.

Had you saved that file as .xls or .xlsm?

Ok, so originally it was .xlsm, however, there was another piece of code (http://www.mrexcel.com/forum/showthread.php?t=573993) that was given to me that didnt seem to work unless it was .xls, everything else I had at the time worked fine on .xls, so I re-saved.

I thought that I would try the before save on the original .xlsm, & it works fine, I suspect that this may be the problem (not that I know why, mind)

So I suppose that my question has now changed, I need both of these things to work on either .xls or .xlsm, it doesn't matter which.
 
Upvote 0
Is the Before_Save event code in the workbook module of the workbook that you are trying to save or in another open workbook ?
 
Upvote 0

Forum statistics

Threads
1,225,152
Messages
6,183,199
Members
453,151
Latest member
Lizamaison

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