ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Excel Got FOcus event (https://www.excelbanter.com/excel-programming/349879-excel-got-focus-event.html)

Xcelion

Excel Got FOcus event
 
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


Ian Digby[_3_]

Excel Got FOcus event
 
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.

--
Work performed in the spirit of service is worship...Baha''''i Writings


"Xcelion" wrote:

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


Xcelion

Excel Got FOcus event
 
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






"Ian Digby" wrote:

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.

--
Work performed in the spirit of service is worship...Baha''''i Writings


"Xcelion" wrote:

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



All times are GMT +1. The time now is 04:34 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com