Excel Got FOcus event

G

Guest

Hi All,

Iam writting an excel addin. I need to trap an event namely got focus for
the excel application. I tried it using the application events. But iam
unable to find a event when the excel application get focus or becomes
active . Is there any event like that.
Please help us.

Thanks in advance
Xcelion
 
G

Guest

You can probably use the Workbook.Activate event: double-click the Workbook
module in the VBE, then select "Activate" from the right-hand drop-down list.
If you are trying to capture the event from outside Excel using the
Application object, you may need to create an Excel class within your
application, then create a WithEvents variable and assign the Excel App to it:

So within your class module (say it's called "CExcel"):
Dim WithEvents xlApp as object

Private Sub xlApp_Activate()
'Your code here...

End Sub

And within your code module:
Dim clsExcel as CExcel
Set clsExcel = New CExcel
Set clsExcel.xlApp = CreateObject("Excel.Application")

Now you should have access to the Excel Activate event.
 
G

Guest

Hi ian,
This works fine when you are switching focus between two excel appliction
instances.But in my case i need to know for instance, when excel gets focus
from another application say word or when excel loses focus
Thanks
Xcelion
 

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