Solved

Email template with variation in subject and attachment

Posted on 2011-03-10
7
141 Views
Last Modified: 2013-11-05
I need to send some emails everyday with almost the same format:
To: someone1@gmail.com
CC: someone2@gmail.com, someone3@gmail.com

Content:
"some text..."

The only difference are:
Subject: Company Report 03-11
Attachment: 2011-03-11 Company Report.xls

Both of the dates will be today's date, and the excel file is already in the same folder "H:\Reports" with correct name

How can I use some VBA to do this automatically? I don't need to send it right away, have to edit something before sending.
0
Comment
Question by:mmcompact
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 35099145
Hi, mmcompact.

This should do it.
Sub SendCannedMessage()
    Dim olkMsg As Outlook.MailItem, strFilename As String
    strFilename = Format(Date, "yyyy-mm-dd") & " Company Reports.xls"
    Set olkMsg = Application.CreateItem(olMailItem)
    With olkMsg
        .To = "someone1@gmail.com"
        .CC = "some2@gmail.com; someone3@gmail.com"
        .HTMLBody = "Some text ..."
        .Subject = "Company Report " & Format(Date, "mm-dd")
        .Attachments.Add "H:\Reports\" & strFilename
        .Recipients.ResolveAll
        .Display
    End With
    Set olkMsg = Nothing
End Sub

Open in new window

0
 

Author Comment

by:mmcompact
ID: 35099662
BlueDevilFan:

Thanks. The HTMLbody is actually a quite long html file. Can I still copy and paste the content there or I need to link to the actual file?
0
 
LVL 76

Expert Comment

by:David Lee
ID: 35100039
I can add code that reads in from the file or you can copy and paste.  You're choice.
0
 

Author Comment

by:mmcompact
ID: 35100404
Read from file will be better. thanks
0
 
LVL 76

Accepted Solution

by:
David Lee earned 500 total points
ID: 35100659
Try this.
Sub SendCannedMessage()
    Dim olkMsg As Outlook.MailItem, strFilename As String, objFSO as Object, objFil As Object
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    'Change the file name on the next line'
    Set objFil = objFSO.OpenTextFile("C:\SomeFileName.htm")
    strFilename = Format(Date, "yyyy-mm-dd") & " Company Reports.xls"
    Set olkMsg = Application.CreateItem(olMailItem)
    With olkMsg
        .To = "someone1@gmail.com"
        .CC = "some2@gmail.com; someone3@gmail.com"
        .HTMLBody = objFil.ReadAll
        .Subject = "Company Report " & Format(Date, "mm-dd")
        .Attachments.Add "H:\Reports\" & strFilename
        .Recipients.ResolveAll
        .Display
    End With
    objFil.Close
    Set objFil = Nothing
    Set objFSO = Nothing
    Set olkMsg = Nothing
End Sub

Open in new window

0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question