Test for opening of a workbook

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I would like some code to run any time any workbook is opened. It wouldn't be very helpful to have to code something in every workbook I creat, so I was wondering if it would be possible to add something to Personal.xls that executes everytime a workbook is opened. I did some searching on Deja, but didn't really find anything. Any help is appreciated

TIA
 
You need to instantiate application level events

see Chip Pearson's site on this

http://www.cpearson.com/excel/AppEvent.htm

You can put this code in your personal.xls

--
Regards,
Tom Ogilvy



John said:
I would like some code to run any time any workbook is opened. It
wouldn't be very helpful to have to code something in every workbook I
creat, so I was wondering if it would be possible to add something to
Personal.xls that executes everytime a workbook is opened. I did some
searching on Deja, but didn't really find anything. Any help is
appreciated.
 
John,

Put this code in the THisWorkbok code module

Dim AppClass As New clsAppEvents

Private Sub Workbook_Open()
Set AppClass.App = Application
End Sub


Then add a class module with this code and name it clsA;ppEvents

Public WithEvents App As Application

Private Sub App_WorkbookOpen(ByVal Wb As Workbook)
MsgBox Wb.Name
End Sub

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

John said:
I would like some code to run any time any workbook is opened. It
wouldn't be very helpful to have to code something in every workbook I
creat, so I was wondering if it would be possible to add something to
Personal.xls that executes everytime a workbook is opened. I did some
searching on Deja, but didn't really find anything. Any help is
appreciated.
 
Thanks for the reply. This will be my first time delving into class modules!
 

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