View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default How to create a shared procedure

What you need to do here is use a Class module to monitor Workbook
events, and use the 'SheetChange' event in there so it applies to all
worksheets in the project workbook. You could even make it apply to
sheets in any other workbook if you put the code in a separate file
(like XLA, for example). This would require checking to make sure the
sheet belongs to your project workbook so it doesn't run the code on
just any worksheet. You could set a class property (or variable)
something like "SheetIsValid" in the 'SheetActivate' event that tells
your 'SheetChange' event if the active sheet is a valid project sheet.
I use a function that returns a boolean value for this, and just pass a
ref to the worksheet. Note that this class 'SheetChange' event also
passes a ref to the sheet (ByVal Sh As Object, ByVal Target As Range).
So you could, for example, implement something like this in the
'SheetChange' event:

If bValidSheet(Sh) Then
'call your sheet change procedure, passing 'Sh' as ref to the sheet
End If

Something of this nature changes the status of your project from a
'glorified workbook with macros' to an Excel addin 'application'. This
means your project workbook won't have to contain any code. It also
gives you a lot more flexibility because revisions to the code don't
effect the project's working file, and vice versa. Also, everyone can
run the addin from a network server, making maintenance an easy chore
over having to redistribute revisons to everyone in your organization.

HTH

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc