Dear Team,
can you help me in sending a mail to my collegues by attaching PDF and Excel file through VB?
have to send seperate mails to everyone with a message body.
sending mail with excel and pdf attachment in outlook by VB
-
- StarLounger
- Posts: 81
- Joined: 21 Apr 2014, 10:45
- Location: Chennai, India
sending mail with excel and pdf attachment in outlook by VB
Regards,
Srinivasan
Srinivasan
-
- gamma jay
- Posts: 25455
- Joined: 17 Mar 2010, 17:33
- Location: Cape Town
Re: sending mail with excel and pdf attachment in outlook by
My VB skills in Outlook is not so hot, so the code on this page should give you a starting point.
Oh... I see you posted in the Outlook forum, but your title refers to emailing with Excel.
in that regard, you will find useful code to use from Ron de Bruin's site here...
Oh... I see you posted in the Outlook forum, but your title refers to emailing with Excel.
in that regard, you will find useful code to use from Ron de Bruin's site here...
Regards,
Rudi
If your absence does not affect them, your presence didn't matter.
Rudi
If your absence does not affect them, your presence didn't matter.
-
- Administrator
- Posts: 78857
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: sending mail with excel and pdf attachment in outlook by
Do you want to send to a group of contacts, or do you have a list of email addresses in for example an Excel workbook?
Best wishes,
Hans
Hans
-
- StarLounger
- Posts: 81
- Joined: 21 Apr 2014, 10:45
- Location: Chennai, India
Re: sending mail with excel and pdf attachment in outlook by
Yes. I have a list of E-mail addresses in an excel workbook.
The attachments (one excel and one pdf) is in a folder.
I want those sheets to be attached in an E-mail and want to send it to each contact seperately.
The attachments (one excel and one pdf) is in a folder.
I want those sheets to be attached in an E-mail and want to send it to each contact seperately.
Regards,
Srinivasan
Srinivasan
-
- Administrator
- Posts: 78857
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: sending mail with excel and pdf attachment in outlook by
Here is a macro you can run from Excel:
Change the constants and the text strings as needed. The code works best if Outlook is already running.
Code: Select all
Sub SendMessages()
Const c = 3 ' column with email addresses
Const strXL = "C:\Excel\MyWorkbook.xlsx"
Const strPDF = "C:\PDF\MyPDF.pdf"
Dim olApp As Object
Dim olMsg As Object
Dim r As Long
Dim m As Long
On Error Resume Next
Set olApp = GetObject(Class:="Outlook.Application")
If olApp Is Nothing Then
Set olApp = CreateObject(Class:="Outlook.Application")
End If
On Error GoTo ErrHandler
m = Cells(Rows.Count, c).End(xlUp).Row
For r = 2 To m
Set olMsg = olApp.CreateItem(0) ' 0 = olMailItem
olMsg.To = Cells(r, c).Value
olMsg.Subject = "My Subject"
olMsg.Body = "My Email Body"
olMsg.Attachments.Add strXL
olMsg.Attachments.Add strPDF
olMsg.Display ' or .Send if you want to send it immediately
Next r
ExitHandler:
Exit Sub
ErrHandler:
MsgBox Err.Description, vbExclamation
Resume ExitHandler
End Sub
Best wishes,
Hans
Hans
-
- StarLounger
- Posts: 81
- Joined: 21 Apr 2014, 10:45
- Location: Chennai, India
Re: sending mail with excel and pdf attachment in outlook by
Many Thanks. It works good!
Regards,
Srinivasan
Srinivasan