Add Action in X at userform macro VBA

abadilala

New Member
Joined
Sep 29, 2017
Messages
27
I have a userform in macro which gets the source from another workbook(test.xlsm). So I used this code below to open that workbook without showing it.
picture :
https://ibb.co/krd66R
<code style="margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace, sans-serif; vertical-align: baseline; white-space: inherit;">Const fromFile = "C:\Users\excel\test.xlsm"
Dim srcBook As Workbook
Set srcBook =
Application
.Workbooks.Open("C:\Users\excel\test.xlsm", _
UpdateLinks
:=False, _
ReadOnly:=True, _
AddToMRU
:=False)</code>
So when the macro run, the userform shown up and also the test.xlsm in background. However, there are some users who close the userform using "X" symbol at the right top corner. and sometimes, there is an error because the source (text.xlsm) didn't close properly.
I am wondering if there is a way to add an action if the user clicks the "X" button in my userform? So I want to close the test.xlsm which run in background if the users click "X" button.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Please take a minute to read the forum rules, especially regarding cross-posting, and then add links here to your cross-posts in other forums. This is not the first time you have cross-posted and failed to provide links, but please make it the last. Thank you.
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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