ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   addin detect worksheet activation (https://www.excelbanter.com/excel-programming/425859-addin-detect-worksheet-activation.html)

Bill Grigg

addin detect worksheet activation
 
All,

How can an addin detect that the user has clicked on a different sheet? Do I
have to somehow put code into the ActiveWorkbook?

Bill

Bob Phillips[_3_]

addin detect worksheet activation
 
Option Explicit

Private WithEvents App As Application

Private Sub App_SheetActivate(ByVal Sh As Object)
'your code here
End Sub

Private Sub Workbook_Open()
Set App = Application
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code


--
__________________________________
HTH

Bob

"Bill Grigg" wrote in message
...
All,

How can an addin detect that the user has clicked on a different sheet? Do
I
have to somehow put code into the ActiveWorkbook?

Bill




Chip Pearson

addin detect worksheet activation
 
I'm assuming you're speaking of an XLA add-in, not a COM or VSTO
add-in.

In the ThisWorkbook module of your XLA project, put in the lines

Private WithEvents App As Application

Private Sub Workbook_Open()
Set App = Application
End Sub

This creates an object named App of type Application that will trigger
all of the events of the application. Every Workbook and Worksheet
event has an Application level counterpart, so every event can be
trapped at the application level. The event that occurs when a user
moves from one sheet to another is the SheetActivate event, so use
code like the following. The Sh parameter is a Sheet object that
references the sheet to which the user just moved.

Private Sub App_SheetActivate(ByVal Sh As Object)
MsgBox "You just moved to:" & vbCrLf & _
"Workbook: " & Sh.Parent.Name & vbCrLf & _
"Worksheet: " & Sh.Name

End Sub


See www.cpearson.com/Excel/AppEvent.aspx for more information about
working with Application events.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)





On Fri, 20 Mar 2009 12:25:01 -0700, Bill Grigg
wrote:

All,

How can an addin detect that the user has clicked on a different sheet? Do I
have to somehow put code into the ActiveWorkbook?

Bill



All times are GMT +1. The time now is 07:47 AM.

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