VBA Check whether file exists on Excel exit.

drefiek2

New Member
Joined
Apr 23, 2023
Messages
48
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Good day,
I need a code which will check whether a particular file exists in a particular folder on Excel exit.
If the file exists it should just close Excel with no popup.
If the file does not exist it should popup with a message. I would like the popup to have a custom message and to have two buttons 'Go Back' or 'I am Viewing Only'. If the latter is clicked Excel should close, if the former is clicked the popup should close and Excel should remain open.
Thank you.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
I would like the popup to have a custom message and to have two buttons 'Go Back' or 'I am Viewing Only'. If the latter is clicked Excel should close, if the former is clicked the popup should close and Excel should remain open.
a) I think you mean the workbook, not necessarily Excel? If you have 2 wb's open and you close one, Excel app is still running.
b) if by popup you mean a standard message box, you cannot have custom button captions and are limited to the built in choices. However, you can present a message that explains which button to click for a particular action.

A workbook has a close event that you can cancel in order to "go back". In that event you'd code to see if the file exists. Research "excel vba check if file exists" and you'll get over a million hits, many/most with code examples. Did you do that and try to cobble something together that works? You could just put the code example in your wb close event (without using the Sub, End Sub lines from the code example).
 
Upvote 0

Forum statistics

Threads
1,215,212
Messages
6,123,651
Members
449,111
Latest member
ghennedy

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