Using Word VBA to send emails not working

Joined
Mar 13, 2013
Messages
1
Reaction score
0
Hi
I am trying to send emails using word vba and outlook. If outlook is running then all is fine. If outlook is not running then the email sits in the outbox until you start outlook, then it is sent.
Office 2010, Win 7.
Relevant code is

'start outlook in the background if not already running
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If
'create and send the email
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
.To = strEmailAddress
.Subject = "Quotation Please"
.Attachments.Add Source:=strFileName & ".pdf"
.Send
End With

'clean up
If bStarted Then
oOutlookApp.Quit
End If
Set oItem = Nothing
Set oOutlookApp = Nothing

The rest of the code builds the string variables and exports the document as a PDF, which I'm happy to post.
Bit stuck, help please

Many thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top