I have two Excel macros workbooks open. While a macro is running in one workbook, and with no action on my part, the other workbook suddenly becomes the ActiveWorkbook. When that happens, VBA references within the running macro of the form:
if Range("RangeName") = True then ....
are resolved by looking for the specified Range Name in the Activeworkbook rather than in the workbook within which to VBA macro is running. If I enter debug mode, manually select the appropriate workbook, and continue macro execution, then all proceeds properly until the other workbook suddenly becomes the Activeworkbook again.
How do I write Excel VBA macro code to explicitly specify the workbook name when referencing the desired Range names?
If ThisWorkbook.Range("RangeName") = True then ...
doesn't work. And I can't figure out how to code
If ThisWorkbook.Sheets("SheetName").Range("RangeName") = True Then ...
without knowing the Sheet name at compile time. And I don't want to hard code both the Sheet Name AND the Range Name. If I close the second workbook, the macro code runs just fine. The running macro requires many minutes to complete. So I'd like to do work in the other workbook while it runs. But just having the second workbook open - even if I don't click to make it active - causes the above behavior.
Any suggestions?