View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
TimDB TimDB is offline
external usenet poster
 
Posts: 3
Default Handling a worksheet calculate event in XLA code

Hi

I have code in a VBA project within an XLA (an Excel add-in written in
Visual Basic for Applications) to be triggered by the Calculate event, and it
works as desired (like when F9 is pressed):


' In Sheet1 within the XLA
Public Sub WorkSheet_Calculate()
' Code here
End Sub

Similarly this works too:

' In ThisWorkbook within the XLA
Public Sub Workbook_SheetCalculate(ByVal Sh As Object)
' Code here
End Sub


The above code works because the "hidden" workbook that forms the XLA
receives the Calculate event (as caused by F9), as do all open workbooks.


However, I need to trigger code within the XLA when a Worksheet_Calculate
event occurs in a worksheet that is part of *another* loaded workbook (not
the XLA), for example, due to pressing <shiftF9 when that worksheet

is active. Currently my code fails because only the active worksheet
receives the calculate event, not the XLA workbook or any of its worksheets.
I have to acheive that without manually copy'n'pasting code into the VBA
project of the other loaded workbook.

So my question is:

Can an XLA in Excel 2007 install an event handler for the
worksheet_calculate event for worksheets in an ordinary workbook when that
workbook is loaded into Excel, and if so, how?

Many thanks
Tim