Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

executing code when Outlook starts 1

Status
Not open for further replies.

AMadden

Technical User
Mar 22, 2002
16
US
I have a VB Script routine that runs (as code behind forms) when I open the contact form in Outlook 2000. The purpose of the code is to load a list of telephone numbers into an array which is used to validate phone numbers in the address book.

It works fine now but I would like to have the routine execute when the Outlook application opens rather than when the contact form opens.

I assume that this will have to be done in VBA rather than the VB Script code behind forms. I have included my VB Script code below followed by a sample of the data file text it reads from a file.

Can anyone give me a pointer on how to convert this to VBA and execute it when Outlook opens? Any help appreciated.

Sample code
--------------------------------------------------
Option Explicit

'global variable holding array of phone numbers not to call
Public strNoCallArray(20000)

Function Item_Open()
Dim strPnumber
Dim fso 'file system object
Dim f 'file
Dim ts 'text stream
Dim c 'counter
'
Dim ArrayIndex
set fso = CreateObject("Scripting.FileSystemObject")
set f = fso.GetFile("c:\donotcall1.txt")
set ts = f.OpenAsTextStream
c = 0
'
Do While Not ts.AtEndOfStream
strPnumber = ""
strPnumber = strPnumber & ts.ReadLine
'remove area code from phone number
strPnumber = """" & Mid(strPnumber, 4, 7) & """"
strNoCallArray(c) = strPnumber
c = c + 1
Loop
'
msgbox("all done")
'
ts.close
End Function

Note that the the text file being loaded is a list of phone numbers in the format:

7278885555
7274449999
7274443333

---------------------------------
Art Madden
amadden@tampabay.rr.com
 
You need to place a call to your code in the startup event.

Place this code in the 'ThisOutlookSession' Module.

Private Sub Application_Startup()
Dim strPnumber
Dim fso 'file system object
Dim f 'file
Dim ts 'text stream
Dim c 'counter
'
Dim ArrayIndex
set fso = CreateObject("Scripting.FileSystemObject")
set f = fso.GetFile("c:\donotcall1.txt")
set ts = f.OpenAsTextStream
c = 0
'
Do While Not ts.AtEndOfStream
strPnumber = ""
strPnumber = strPnumber & ts.ReadLine
'remove area code from phone number
strPnumber = """" & Mid(strPnumber, 4, 7) & """"
strNoCallArray(c) = strPnumber
c = c + 1
Loop
'
msgbox("all done")
'
ts.close

End Sub


All I've done is copy your code into the sub, looks like it should work.

Since this isn't vb script anymore, you can early bind your variables...

Dim fso As FileSystemObject
set fso as New FileSystemObject

HTH
 
Many thanks, that was just the help I needed. I found that my declaration of a Public string array caused an error if used in the "This Outlook Session" section." But I was able to get around this by placing my original code in a separate module and calling it from the Application_Startup routine. Thanks again. ---------------------------------
Art Madden
amadden@tampabay.rr.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top