VBA - close workbook when click on MsgBox

Yulyo

Board Regular
Joined
Jul 17, 2017
Messages
94
Hello all,

Short question regarding a VBA, since i am a novice :)

I have a longer VBA that automatically opens the newest file in a folder and looks for a sheet, by name.
If the sheet is found, it will activate the sheet - until now everything works just fine.

Now, if the sheet is not found, it gives me an error.
I manage to change the VBA, to give me a message that the sheet was not found in workbook.
Now i want to change it again, so that when i click ok on the msgbox, to close the workbook.

This the end part of my code:

VBA Code:
Workbooks.Open MyPath & LatestFile, ReadOnly:=True
If Evaluate("isref('xxx'!A1)") Then
Worksheets("xxx").Activate
Else
MsgBox "Sheet not found."
End If

If needed i will paste the entire code, of course.
Thank you
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Just add
VBA Code:
ActiveWorkbook.Close
straight after the msgbox.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,542
Members
449,316
Latest member
sravya

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