PDA

View Full Version : Email with outlook using vba



gc89
07-07-2015, 02:45 PM
Hi,

I have this excel file which I would like to email the contents of the scorecard sheet in outlook in the body with/without attachment.
I have used your previous macro and modify it a bit but it doesn't work :(
I'm quite new with macro so not sure where went wrong but I got error 1004 when I tried to run the vba.
Need your kind help!

p45cal
07-13-2015, 07:27 PM
It seems to largely work here; I got no error 1004, but I did get an error 400 which turns out on my Windows 7, Excel 2010 (32 bit) to be caused by this code (where I have commented out the lines giving trouble):

With .Cells(1)
'.PasteSpecial Paste:=8 '8 as table
.PasteSpecial xlPasteValues, , False, False
'.PasteSpecial xlPasteFormats, , False, False
.Select
End With


You seem to be missing some of Ron de Bruin's code to attach files to the email; you need to add the following snippet of his just before:

'Resolve each Recipient's name.
missing lines:
' Add attachments to the message.
If Not IsMissing(strAttachmentPath) Then
If Len(Dir(strAttachmentPath)) <> 0 Then
Set objOutlookAttach = .Attachments.Add(strAttachmentPath)
Else
MsgBox "Unable to find the specified attachment. Sending mail anyway."
End If
End If