Verify name of active workbook. If incorrect, message box and then close without saving

jase71ds

Board Regular
Joined
Oct 23, 2006
Messages
137
Office Version
  1. 365
Platform
  1. Windows
Hi all.
I'll say in advance that I always appreciate your time and help. Today is no different, so thanks!

I have a templated macro file named: "VTA Report.xltm".
The user needs to right-mouse-click and select "Open" from the contextual menu.
So...
As soon as they try to run the macros (assigned to a button) I'd like for Excel to check and see if the name of the active workbook is "VTA Reports.xltm". If they opened it by merely double-clicking the name will be "VTA Reports1.xlxm"

So, Active Workbook should = "VTA Reports.xltm"
If not, then Msg Box("yada, yada")
Then quit the file without saving: Application.Quit

Thanks for any help.
Jase.
 
Try

Code:
If ActiveWorkbook.Name <> "VTA Reports.xltm" Then
    MsgBox "Wrong file", vbexclanation
    ActiveWorkbook.Close False
    Application.Quit
End If
 
Upvote 0
Great. Thanks so much. I'm going to try the code at lunchtime.
 
Upvote 0
Just spotted a typo

Rich (BB code):
If ActiveWorkbook.Name <> "VTA Reports.xltm" Then
    MsgBox "Wrong file", vbExclamation
    ActiveWorkbook.Close False
    Application.Quit
End If
 
Upvote 0
Okay, I tried it. It works great!
Much appreciated!!!
 
Upvote 0

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