Hope this helps. It will take the name of multiple recipients separated by semi-colons( it'll cc those after the first ) and attach the file stored in attachment to each email. It'll then send it to everyone.
Private Sub SendEmail(recipient As String, attachment As String)
On Error GoTo Err_Sub
Dim line As Integer
Dim place As Integer
Dim firstdone As Boolean
Dim ccname As String
Dim rcpname As String
Dim ccstring As String
firstdone = False
Dim ol As Outlook.Application
Dim olmsg As Outlook.MailItem
Dim olrcp As Outlook.recipient
Dim olatt As Outlook.attachment
Set ol = CreateObject("outlook.application"
Set olmsg = ol.CreateItem(olMailItem)
With olmsg
place = InStr(recipient, ";"
If place = 0 Then
Set olrcp = .Recipients.Add(recipient)
olrcp.Type = olTo
Else
ccstring = recipient
Do
rcpname = Left(ccstring, place - 1)
If Len(rcpname) > 0 Then
If firstdone = False Then
Set olrcp = .Recipients.Add(rcpname)
olrcp.Type = olTo
firstdone = True
Else
Set olrcp = .Recipients.Add(rcpname)
olrcp.Type = olCC
End If
End If
ccstring = Right$(ccstring, Len(ccstring) - place)
place = InStr(ccstring, ";"
Loop Until place = 0
If Len(ccstring) > 0 Then
Set olrcp = .Recipients.Add(ccstring)
olrcp.Type = olCC
End If
End If
.Subject = "Email Subject"
.Body = "This email should contain an attachment"
Set olatt = .Attachments.Add(attachment)
For Each olrcp In .Recipients
olrcp.Resolve
Next
.Save
.Send
End With
Exit_Sub:
Set ol = Nothing
Exit Sub
Err_Sub:
MsgBox Err.Description, , "Sending Email line " + Str(line)
Resume Exit_Sub
End Sub
that worked a treat, I've been through the visual basic programmers guide and copied in their sample code but it falls over on the attachment element . .
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.