I just need a message box to appear after someone saves the Excel document. The message box will only have text and probably an "OK" button for the user to press. The box itself is completely independent from the "save", meaning that once the user pressed "save", the document is saved regardless if the user presses "OK" in the message box.
So it's a pretty simple message box but when I looked on forums, the message boxes introduced were a little too complex for my simple request.
Another item, can you inform me what I need to change to make the message box appear if someone closes the Excel spreadsheet? So rather than pressing Save, what if they close the spreadsheet. So please help with these two requests.
Thanks so much.
If I understand correctly, put this in the ThisWorkbook module (see VBE Project window):
and this in a normal modulePrivate Sub Workbook_BeforeClose(Cancel As Boolean) x End Sub Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) x End Sub
But what is the point of this?Sub x() MsgBox "Text here", vbOKOnly End Sub
Last edited by StephenR; 11-17-2010 at 11:03 AM.
Hello
I'll assume you've never used VBA in your life. Open up VBA (press ALT+F11 from Excel). In the Project Explorer double click "ThisWorkbook". If you can't see this make sure the Project Explorer is visible by going to View > Project Explorer. Then maximize the folder "Microsoft Excel Objects". "ThisWorkbook" should be there.
A blank page will open. Near the top there should be two drop down boxes. The first should say "(General)". Change this to "Workbook" then select "BeforeSave". This event is fired when the user saves the document.
In the sub that appears add your message box. E.g.:
Private Sub Workbook_BeforeClose(Cancel As Boolean) MsgBox "Your message.", vbOKOnly, "Your title" End Sub
For when the user closes the workbook. Do the same but this time choose "BeforeClose" and stick your code in that new sub. E.g.:
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) MsgBox "Your message.", vbOKOnly, "Your title" End Sub
EDIT: Sorry, StephenR beat me to it.
Last edited by ReportMaker; 11-17-2010 at 11:07 AM. Reason: Slow
Thanks! It worked. The purpose is that this spreadsheet is going out to 800+ people to fill out information. After they save, I want them to read a message to remind them the importance of certain data. I don't want to put additional formatting/calculation into the spreadsheet because it'll just slow the thing down. So I just want a simple message box.
You will probably be better off in this situation to use Conditional Formatting and/or Data Validation to ensure correct input. If a user doesn't enable macros then your warning messages won't appear.
If you are satisfied with the solution(s) provided, please mark your thread as Solved.
How to mark a thread Solved
Go to the first post
Click edit
Click Go Advanced
Just below the word Title you will see a dropdown with the word No prefix.
Change to Solved
Click Save
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks