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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript and Outlook 2003

Status
Not open for further replies.

fredjonze

Technical User
Apr 9, 2001
38
0
0
US
Hi,
I have a script that no longer works with Outlook 2003. Used to work before the upgrade. Has MS changed the object model for Outlook 2003? I get a "Variable is undefined: 'olMailItem'"

Sub SendMailOutlook(aTo, Subject, TextBody, aFrom, aAttachment)

'Create an Outlook object
Dim Outlook 'As New Outlook.Application
Set Outlook = CreateObject("Outlook.Application")

'Create e new message
Dim Message 'As Outlook.MailItem
Set Message = Outlook.CreateItem(olMailItem)
With Message
'You can display the message To debug And see state
.Display

.Subject = Subject
.Body = TextBody

'Set destination email address
.Recipients.Add (aTo)

.Attachments.Add (aAttachment)

'Set sender address If specified.
Const olOriginator = 0
If Len(aFrom) > 0 Then .Recipients.Add(aFrom).Type = olOriginator

'Send the message
.Send
End With
End Sub


Thanks,
 
Hello fredjonze,

Does the environment recognize olMailItem=0? or you need to define it explicitly?

regards - tsuji
 
Hi,

The script ran fine on Outlook 2002 but does not run with Outlook 2003. Has the object model changed?

 
fredjonze,

I do not think the line is of a syntax proper to vbs, so I would be surprised it ever works in a standalone vbs/wsh. You should have been running vb application or vba environment?

To make it work, you have to change the .type construction down there as well. With that, you can run it across versions.
Code:
    'Set sender address If specified.
    Const olOriginator = 0
    If Len(aFrom) > 0 Then
         set oRecipient=.Recipients.Add(aFrom)
         oRecipient.Type = olOriginator
         oRecipient.resolve
    End If
- tsuji

 
fredjonze
IMHO the problem is not in object model but in script environment: seems you have now Option Explicit.
So just try something like this :
Dim Message 'As Outlook.MailItem
Const olMailItem = 0
Set Message = Outlook.CreateItem(olMailItem)

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top