View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Patrick Molloy[_2_] Patrick Molloy[_2_] is offline
external usenet poster
 
Posts: 1,298
Default Event in a add-in called verytime a file is opened

This is an application level event, never-the-less relatively simple.

with your XLA add a Class Module with this code

Option Explicit
Public WithEvents xl As Excel.Application
Private Sub Class_Initialize()
Set xl = Excel.Application
End Sub
Private Sub xl_WorkbookOpen(ByVal Wb As Workbook)
MsgBox "Book Opened"
''' call your code from here
End Sub

call the class cXL

You need a standard code module with code that inclused this...

Option Explicit
Public xl As cXL
Sub Auto_Open()
Set xl = New cXL
End Sub


now, when you XLA loads, its auto_open sub is called, which sets the class
cXL to the actice Ecel application./ Now, whenever a workbook is opened, the
cXL's class event will fire, raising the message....just replace this by a
call to whatever sub you want.

Demo file available

Patrick Molloy
Microsoft Excel MVP








"Torben Laursen" wrote:

Hi

I have a add-in and I want it to run a check each time the user open a file
in Excel to see if it has a sheet called Project. If it does it has to run
some code.

But I cannot find the event to use, can anyone help me?

Thanks!
Torben Laursen