Add one attach file to Outlook message

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
giovanniroi
Junior Coder
Posts: 21
Joined: Fri Jul 03, 2009 4:36 pm
Location: Milan,Italy

Add one attach file to Outlook message

Post by giovanniroi » Sun Jul 05, 2009 4:46 pm

I use the sample script modified to send one mail from outlook and I try to modify to send one attach file but this code don't working. (see the error code in this mail)
Can You help me to correct the script?
My script is this:
------------------------------
Function CreateEmail(strRecipient, strSubject, strBody, strAttach)
'Create OL App object
Set objOLApp = CreateObject("Outlook.Application")

If objOLApp is nothing then
MsgBox "Could not create OL App. Shutting Down"
Exit Function
End If

'Create a new mail item
Set objMsg = objOLApp.CreateItem(0)
If objMsg is nothing then
MsgBox "Could not create Mail Item. Shutting Down"
Exit Function
End If

'Set basic message parameters
objMsg.To = strRecipient
objMsg.Subject = strSubject
objMsg.Body = strBody
objMsg.attach = strAttach


'Send the message
objMsg.Send

'Free up the space
Set objOLApp = Nothing
Set objMsg = Nothing

CreateEmail = "Success"
End Function
VBEnd

let>strTo=[email protected]
let>strSubj=Elenco errori
let>strBody=Questo è l'elenco errori
let>strAttach=C:\GR&A_Trend\Messaggi_errore\TLS90_Monitor_errori_applicazione.xls

VBEval>CreateEmail("%strTo%","%strSubj%","%strBody%","%strAttach%"),Answer
------------------------------


The error is : Run time error 438 Proprity or metod don't supported by the object: objMsg.attach

Thank's

Giovanni

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Tue Jul 21, 2009 11:36 am

There was a similar question in another thread recently. The correct syntax is:

objMsg.Attachments.Add(attachment_file)
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Suggested format works for attachments by index

Post by gdyvig » Tue Jul 21, 2009 1:37 pm

Here is a link to that other thread about Outlook attachments.

http://www.mjtnet.com/usergroup/viewtop ... 4790#24790

The syntax Marcus refers to only works for attachments referenced by index, not by value as done in your script.

The thread also contains two more links supplied by Marcus that gives additional detail.

See the last post in that thread for the syntax of attachment by value. I tried it out, it works with some caveats.

One of the caveats applies in your case:
let>strAttach=C:\GR&A_Trend\Messaggi_errore\TLS90_Monitor_errori_applicazione.xls
The MSDN documentation says you are sending a copy of the attachment, not a link. But if you try to open the attachment you get a file not found error on the recipients machine but not on the senders machine. I I suspect that if the file was a network share accessible by both the sender and the recipient it could be opened by either.

Gale

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts