Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Inserting Open Event code via VBA

Hi all

I wish to write a routine that adds the following code to apprimately 300
files

"Private Sub Workbook_Open()
Dim YearsService As Single
YearsService = Now() - Range("Start_Date")
MsgBox Range("First_Name") & " " & Range("Surname") & " has a service
record of " & _
Int(YearsService / 365) & " years and " & Int((YearsService Mod 365) /
31) & " months"
End Sub"

At the moment there is no Open Event code in the files

I already have the routine to open the files one by one, make standard
changes, (heading etc.) and save the files. That part works fine.

However, now the client wants me to add an Open Event such as the above
code.
I had a look at John Walkenbach's book on adding code to a Module or adding
a button but can't find a way of inserting the above into ThisWorkBook.

Thanks,
Peter Bircher
Kwazulu-Natal, SA



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Inserting Open Event code via VBA

I guess you mean insert it using code?

http://www.cpearson.com/excel/vbe.htm
discusses this.

--
Regards,
Tom Ogilvy



"Pete" wrote:

Hi all

I wish to write a routine that adds the following code to apprimately 300
files

"Private Sub Workbook_Open()
Dim YearsService As Single
YearsService = Now() - Range("Start_Date")
MsgBox Range("First_Name") & " " & Range("Surname") & " has a service
record of " & _
Int(YearsService / 365) & " years and " & Int((YearsService Mod 365) /
31) & " months"
End Sub"

At the moment there is no Open Event code in the files

I already have the routine to open the files one by one, make standard
changes, (heading etc.) and save the files. That part works fine.

However, now the client wants me to add an Open Event such as the above
code.
I had a look at John Walkenbach's book on adding code to a Module or adding
a button but can't find a way of inserting the above into ThisWorkBook.

Thanks,
Peter Bircher
Kwazulu-Natal, SA




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Inserting Open Event code via VBA

Check out this link...

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

--
HTH...

Jim Thomlinson


"Pete" wrote:

Hi all

I wish to write a routine that adds the following code to apprimately 300
files

"Private Sub Workbook_Open()
Dim YearsService As Single
YearsService = Now() - Range("Start_Date")
MsgBox Range("First_Name") & " " & Range("Surname") & " has a service
record of " & _
Int(YearsService / 365) & " years and " & Int((YearsService Mod 365) /
31) & " months"
End Sub"

At the moment there is no Open Event code in the files

I already have the routine to open the files one by one, make standard
changes, (heading etc.) and save the files. That part works fine.

However, now the client wants me to add an Open Event such as the above
code.
I had a look at John Walkenbach's book on adding code to a Module or adding
a button but can't find a way of inserting the above into ThisWorkBook.

Thanks,
Peter Bircher
Kwazulu-Natal, SA




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Inserting Open Event code via VBA

Thanks, Tom.
I had a look and it looks perfect - I am pretty sure it will do just fine.
Peter

"Tom Ogilvy" wrote in message
...
I guess you mean insert it using code?

http://www.cpearson.com/excel/vbe.htm
discusses this.

--
Regards,
Tom Ogilvy



"Pete" wrote:

Hi all

I wish to write a routine that adds the following code to apprimately 300
files

"Private Sub Workbook_Open()
Dim YearsService As Single
YearsService = Now() - Range("Start_Date")
MsgBox Range("First_Name") & " " & Range("Surname") & " has a service
record of " & _
Int(YearsService / 365) & " years and " & Int((YearsService Mod 365)
/
31) & " months"
End Sub"

At the moment there is no Open Event code in the files

I already have the routine to open the files one by one, make standard
changes, (heading etc.) and save the files. That part works fine.

However, now the client wants me to add an Open Event such as the above
code.
I had a look at John Walkenbach's book on adding code to a Module or
adding
a button but can't find a way of inserting the above into ThisWorkBook.

Thanks,
Peter Bircher
Kwazulu-Natal, SA






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Inserting Open Event code via VBA

Also, thanks to you, Jim for the timely response.
As mentioned in the reply to Tom, I had a look and it looks like it will do
just fine.
Peter

"Jim Thomlinson" wrote in message
...
Check out this link...

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

--
HTH...

Jim Thomlinson


"Pete" wrote:

Hi all

I wish to write a routine that adds the following code to apprimately 300
files

"Private Sub Workbook_Open()
Dim YearsService As Single
YearsService = Now() - Range("Start_Date")
MsgBox Range("First_Name") & " " & Range("Surname") & " has a service
record of " & _
Int(YearsService / 365) & " years and " & Int((YearsService Mod 365)
/
31) & " months"
End Sub"

At the moment there is no Open Event code in the files

I already have the routine to open the files one by one, make standard
changes, (heading etc.) and save the files. That part works fine.

However, now the client wants me to add an Open Event such as the above
code.
I had a look at John Walkenbach's book on adding code to a Module or
adding
a button but can't find a way of inserting the above into ThisWorkBook.

Thanks,
Peter Bircher
Kwazulu-Natal, SA






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
Which 'event' to run pivot chart formatting code on file open? David Charts and Charting in Excel 1 June 11th 09 02:22 PM
What code do I use to attach event handler that will open my user. TeresaManley Excel Worksheet Functions 2 May 5th 07 09:55 PM
Inserting a worksheet into an open workbook via VBA code manillla Excel Programming 2 June 14th 05 01:30 AM
Insert VBA code with a macro in a .xls file by workbook open event mihai[_3_] Excel Programming 8 July 29th 04 01:49 PM
Open Event Code Bug Tim[_36_] Excel Programming 4 April 26th 04 08:51 AM


All times are GMT +1. The time now is 11:08 PM.

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"