0 votes
in VBA by Beginner (4 points)
Hi, I am trying to trigger and event when I either

#1 switch workbooks and reselect the original workbook or

#2 switch applications, say to IE, and then reselect the original workbook

 

I have tried all sorts of variations using workbook activate / window activate events, but the event does not trigger unless moving withing the original workbook

Any ideas gratefully accepted

Regards

James

1 Answer

0 votes
by Beginner (35 points)

This is really interesting to read about. I did some testing on various methods (using Timer and Do Events, etc.) but I couldn't get anything to work. It looks like the only method that works is using windows API. Look at https://www.excelforum.com/excel-programming-vba-macros/1043238-test-if-application-has-focus.html and see if this can help you out. I'll keep trying something but this is the only partial answer I can seem to get. I haven't been able to get it to continuously check for focus, or to trigger when the window focuses, but It is a start. Let us know if you get this to work out any more.

Welcome to wellsr Q&A
wellsr Q&A is the VBA and Python programming community that rewards you for learning how to code.

Getting Started
Register
VBA Cheat Sheets (On Sale Now)

Earn free prizes for asking VBA and Python questions and for answering questions asked by others in our community.

Looking for something else? Hire our professional VBA Help, instead.

What makes us different?
Our points system rewards you with a chance for free gifts based on the quality of your questions and answers. All you have to do is post and you could get rewarded, like these members:

ParserMonster $25 Amazon Gift Card
Hightree $10 Amazon Gift Card
Thales1 $10 Amazon Gift Card
runfunke $10 Amazon Gift Card
coolag $10 Amazon Gift Card
Siew Hun $10 Amazon Gift Card

So, why don't you join us? It really is an encouraging way to motivate members in our VBA and Python community.

Register

For more programming tips visit the VBA Tutorials Blog and the Python Tutorials Blog.

...