Excel VBATutorial                                   Tutorial on Excel macros

 

Excel VBA Macros

Excel Macros Table of Contents

Excel Visual Basic Editor

Excel Macros Vocabulary

Excel Userforms

Excel Consulting

Excel Tutorial on Macros

Email to excel-vba.com

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

Excel Tutorial on Macros

Excel VBA Macros

Excel Macros Table of Contents

Excel Visual Basic Editor

Excel Macros Vocabulary

Excel Userforms

Excel Consulting