Is ActiveSheet in ThisWorrkbook?

C

Charlotte E.

Is there a way to check if ActiveSheet is part of the workbook in which
the a macro is located?

I have a macro which switches between 3 open workbooks, and for some
reason the activesheet also switches...

How to check if ActiveSheet is in ThisWorkbook or in ActiveWorkbook?


Thanks,

CE
 
J

Jim Cone

More...
You do not have to activate a workbook in order to run code.
"Workbooks(2).Sheets(3).Range("A1").value2 = 1234" runs just fine without activating/selecting that
workbook.

If you do have to determine if the workbook with code is active then...
"ActiveSheet.Parent Is ThisWorkbook" returns True or False.
'---
Jim Cone


"Jim Cone" <[email protected]>
wrote in message
 
P

Pierre Leclerc

Indeed the ActiveSheet is always in the ActiveWorkbook because both are visible on screen.

ThisWorkbook is the workbook within which the macro runs and the ActiveSheet is not necessarily in ThisWorkbook.

To check such a fact use an if statement:

If ActiveWorkbook.Name=ThisWorkbook.Name then.....

See all about these workbooks in my tutorial at www.excel-vba.com

Peter
 
S

simpleMacros

Indeed the ActiveSheet is always in the ActiveWorkbook because both are visible on screen.

ThisWorkbook is the workbook within which the macro runs and the ActiveSheet is not necessarily in ThisWorkbook.

To check such a fact use an if statement:

If ActiveWorkbook.Name=ThisWorkbook.Name then.....
 

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

Top