Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Event in a add-in called verytime a file is opened

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Event in a add-in called verytime a file is opened

Hi Patrick

Thanks for the code.
What do I need to do so I can use the Auto_Open function that you give.

If I have it in I get a error when opening a file for the first time:
"Ambiguous name detected: Auto_Open".
I have check the code and there is only one function called Auto_Open.

Is there some other way that I can run the code inside Auto_Open?

Thanks
Torben Laursen

"Patrick Molloy" wrote in message
...
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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Event in a add-in called verytime a file is opened

I'd double check.

In the VBE, ctrl-f (but find in the project--not just a single module).



Torben Laursen wrote:

Hi Patrick

Thanks for the code.
What do I need to do so I can use the Auto_Open function that you give.

If I have it in I get a error when opening a file for the first time:
"Ambiguous name detected: Auto_Open".
I have check the code and there is only one function called Auto_Open.

Is there some other way that I can run the code inside Auto_Open?

Thanks
Torben Laursen

"Patrick Molloy" wrote in message
...
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




--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
When I open a workbook, another one called Book1 is also opened. W Ian@MarlandLtd Excel Discussion (Misc queries) 2 November 9th 05 09:36 AM
why is an Excel file called a workbook? Monique Excel Discussion (Misc queries) 3 October 14th 05 05:52 PM
Returning From VBA Event Code Called From Excel 4.0 Macro jj Excel Programming 0 July 12th 04 04:30 PM
Userform_Initialize event failing to be called R Avery Excel Programming 2 March 3rd 04 04:06 AM
Save Event - Determine if called by code or user David Sedberry Excel Programming 0 October 2nd 03 04:56 PM


All times are GMT +1. The time now is 02:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"