Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Worksheet activation on Opening Workbook | Excel Programming | |||
Detect New Worksheet being added | Excel Programming | |||
Worksheet Activation from another workbook | Excel Programming | |||
To detect changes in a worksheet | Excel Programming | |||
detect worksheet | Excel Programming |