If statement depending on NAME of workbook

  • Thread starter Thread starter rob nobel
  • Start date Start date
R

rob nobel

I would like certain events to occur depending on what the name of the
workbook is. Is there a way to do this?
What would be the code for this?
Can something like if WorkbookName = "Name" Then
Or am I totally out of whack here?
Rob
 
rob,

You can use either
ThisWorkbook.Name
or
ActiveWorkbook.Name

e.g.
If ThisWorkbook.Name = "Test.xls" Then
' do something
Else
' do something else
End If

John
 
John, I think I tried nearly every combination of ActiveWorkbook and
WorkbookName (as suggested in helps) until I went completely bald! But
ThisWorkbook. Name works great! Is there a section in Help that gives all
the possible variants so I could cruise through the list and select
something that may work?
Thanks,
Rob
 
rob,

There's really no "section" of 'possible variants' in Help that I know of.
A search in Help for "Workbook Name" should get you to the .Name
property and that would have started you in the right direction.
You kind of have to have an idea of what you're looking for before
searching through it though.

In this particular case, you'd need to know that "ThisWorkbook" or
"ActiveWorkbook" was your key. From the VBA Editor, if you typed
"ThisWorkbook." you'd get a list of all the associated arguments
that could follow.

Personally, I find that searching the Excel newsgroups in Google
will turn up a lot more answers and examples than MS could ever hope to
duplicate in "Help".

Have you happened upon Ron de Bruin's Add-In for Google searches???

http://www.rondebruin.nl/Google.htm

Might prove to be a very worthwhile addition to your library of Excel tools.

John
 

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