Link to home
Start Free TrialLog in
Avatar of Ian Bell
Ian BellFlag for United Kingdom of Great Britain and Northern Ireland

asked on

message box

Hi,
I have lost an Excel file several times for not disconnecting an API program.
Therefore I would like a message box saying "Have you logged off?" that appears when I try to close the Excel workbook. This will act as a reminder and save me from hours of file reconstruction.
Many thanks
Ian
ASKER CERTIFIED SOLUTION
Avatar of Shums Faruk
Shums Faruk
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I was wondering, when you make changes in any workbook and if you tries to close that workbook, there is default prompt for saving, do you still need above custom msg box?
Avatar of Ian Bell

ASKER

Hi Shums,

Firstly I don't need any msg box for other files but thanks for asking.

Secondly, As I am not so familiar with VBA can you guide me step by step to copy the above code.
thanks
Ian
If I select 'yes' I would like to save and exit. Can that be done ?
As per your initial request you did asked for Message Box:
I would like a message box saying "Have you logged off?"
:)

If you are working on one workbook for API Program, then make sure your workbook is saved as .xlsm.

Press Alt+F11 to open visual basic, in project window you will see ThisWorkbook, double click and paste above code.

If you select yes it will be saved, but if its not with xlsm extension, it will not save.
Oh sorry, I meant I have only one workbook that needs the message box
Alt F11 only brings up 'immediate window'
Click on View/Project Explorer, you will see below window:
User generated image
Yes working fine Shums and thanks again for a quick and professional outcome
Ian
You're always welcome Ian! :)