Add-in to run macro when ANY workbook is opened?

  • Thread starter Thread starter jruppert
  • Start date Start date
J

jruppert

i would like to create an add-in that runs when any workbook is opened
I didnt think i could use the workbook_open code b/c that would have t
reside in the individual workbooks, am i wrong in that assumption?

thanks
 
You'll have to set a reference to the application object
AND monitor the application events. You could create a classmodule but
following is simpler.


in the addin's Thisworkbook object module:

Option Explicit

Dim WithEvents xlApp As Application

Private Sub Workbook_Open()
Set xlApp = Application
End Sub

Private Sub xlApp_SheetSelectionChange(ByVal Sh As Object, _
ByVal Target As Range)
If Target.Address <> "$A$1" Then
Sh.Cells(1).Select
End If
End Sub


instantiate the xlapp variable by running the workbook_open procedure
(once) then try to navigate your workbooks :)


keepITcool

< email : keepitcool chello nl (with @ and .) >
< homepage: http://members.chello.nl/keepitcool >
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top