Questions and Answers on Excel Macros
Level: Intermediate
Topic: Is ActiveSheet in ThisWorkbook?
Question:
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?
Answer:
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.....
To learn everything about all these workbooks and how to move from one to the other see lesson 14 of my Downloadable Tutorial on Excel Macros
To send your questions or comments click here
Back to Q&A on Excel Macros
|