Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

autoexec macro in excel. Does it exist.

Status
Not open for further replies.

MikeCDPQ

Technical User
Sep 11, 2003
173
CA
Is there a name I can give an excel macro so that it gets performed when a workbook is closed just before the save takes place.

Basically, I want my users to be able to filter and sort the sheet and bring changes to cells but I don't want the sort and filter to be save with the rest of the changes.

Autoexec, Autoclose ... there must be something out there :)

Any suggestions ?

Thanks
 
Mike,

In VBA Project in the Workbook Object is a BeforeSave event. Call your procedure from that event
Code:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
   YourMacro
End Sub
:)


Skip,
Skip@TheOfficeExperts.com
 
Thanks Skip,

Not having too much luck. I was not getting anywhere with your code. After I knew to look for beforeclose or beforesave in VBA help, I found the code here bellow and I simply copied it and even threw in my name to be sure I was getting the right message.


Private Sub app_workbookBeforeClose(ByVal WB As Workbook, _
Cancel As Boolean)
a = msgbox("Do you really want to save the workbook Mike?", vbYesNo)
If a = vbNo Then Cancel = True
End Sub




The problem is I want to save that on a particular workbook but I can't do that because of the way the security is set at my work. (Macros in this workbook are disabled because the security level is high.....)

I cannot as a user modify the security level.

Is there a way to have the same script in a shared macro and refer to the name of my workbook.

Thanks again for your help.

Mike

 
In your workbook that has the high security...

Tools/macro/Security/Security Level Tab - select Medium.

Save and close

Open

Now, proceed with your workbook_BeforeSave event.

Skip,
Skip@TheOfficeExperts.com
 
SkipVought

I know about the security issue. As I said, I cannot change it. Well I can but when I go back it has reverted back to high. That's the way the IT Dept decided it.

I will have about 25 users using this macro and I very much doubt IT will be willing to change the level of security for so many users.

So back to my question, do you think there's a way to refer to the workbook from within this script ???

Thanks you ever so much for your time and effort. Extremely appreciated.

Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top