PDA

View Full Version : Add attachment to email



spgprivate
02-21-2013, 01:08 PM
Hi

New to VBA but enjoying learning...

Got stuck though when trying to create new mail from a button in word which adds the doc into the new mail created. Heres what Ive got so far:

Private Sub CommandButton1_Click()
'Get Outlook if it's running
Set oOutlookApp = GetObject(, "Outlook.Application")
If Err <> 0 Then
'Outlook wasn't running, start it from code
Set oOutlookApp = CreateObject("Outlook.Application")
bStarted = True
End If

'Create a new mailitem
Set oItem = oOutlookApp.CreateItem(olMailItem)
With oItem
'Set the recipient for the new email
.To = "simon.grumbt@bt.com"
'Set the recipient for a copy
.CC = "simon.grumbt@bt.com"
'Set the subject
.Subject = "Trial Feedback"
'The content of the document is used as the body for the email
.Body = ActiveDocument.Content
.Display
End With
If bStarted Then
'If we started Outlook from code, then close it
oOutlookApp.Quit
End If
'Clean up
Set oItem = Nothing
Set oOutlookApp = Nothing
End Sub

The body of the doc is embedded as per above command which I need to replace with one that attaches the doc itself? Ive heard of SendMailAttach but can find the correct method

Si

fumei
02-21-2013, 06:10 PM
If you using IntelliSense, try .Attachment (or something like that) with your MailItem. I no longer use Outlook, so I can not look things up in detail.

Please use the VBA tags when posting code.