Is Active Workbook ="ABC"

  • Thread starter Thread starter Otto Moehrbach
  • Start date Start date
O

Otto Moehrbach

Excel 2002, WinXP
I have a user-created menu item that is applicable to only one file. That
menu item is created/deleted by code that is in that one file. However,
other files may be open at the same time and I need to make sure that this
one file, "ABC", is the active file before executing the menu item code.
I thought that ThisWorkbook was always the active file but it isn't.
ThisWorkbook is the file that holds the macro that is being executed.
How do I check for the active file, as in:
If (the active file).Name <> "ABC" Then MsgBox "Wrong File"
Thanks for your help. Otto
 
Otto,

Try something like

If ActiveWorkbook.Name <> "ABC.xls" Then
' wrong file
End If

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
Hi Otto;

Use the call

ActiveWorkBook.Name

It might look something like this:

Sub Try ()

If ActiveWorkBook.Name = "MyWorkBookName" then
'do your menu stuff here
End If
End Sub
 
I responded but I haven't seen it posted. I'll try again. Otto

Thanks Chip. I knew it had to be something simple. Otto
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top