Word-Outlook error "Object variable or With block variable not set

M

muybn

On the line with "objAttach.Add" below, I am trying to make an attachment to
an e-mail created from the Word doc, but it throws the error "Object variable
or With block variable not set," whether in or outside of the "With objItem"
section. Any suggestions?

Dim objOutlookApp As Outlook.Application, objItem As Outlook.MailItem
Dim objAttach As Attachments
Dim objItem As Outlook.MailItem
Set objItem = objOutlookApp.CreateItem(olMailItem)
With objItem
.Save
objAttach = objItem.Attachments
objAttach.Add "C:\Data\misc\jbz\" & strDoc & ".doc"
.BodyFormat = olFormatHTML
.To = strE
.Subject = strDoc
.Display
End With
Set objItem = Nothing
Set objOutlookApp = Nothing
Set objAttach = Nothing
 
D

Doug Robbins - Word MVP

Use

With objItem
.Attachments.Add "C:\Data\misc\jbz\" & strDoc & ".doc",
olByValue, 1
'etc
End With

See the article "How to send an email from Word using VBA" at:

http://www.word.mvps.org/FAQs/InterDev/SendMail.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
M

muybn

Perfect, thanks. This did the trick. Interesting, since what I had written
was almost verbatim in format to a MS help page.
 
Top