Hello,
I have a macro that grabs a specific email template then attaches a specific PDF file to it then sends it all off without display.
Here's the code:
<code>
Dim objOL As Outlook.Application, msg As MailItem, p$, i%, ap$
'Below is the location of the all the workflows on the network
ap = "\\fleet.ad\Data\Data1\VMSSHARE\Team GE Workflows"
Set objOL = CreateObject("Outlook.Application")
On Error Resume Next
For i = 1 To Range("B" & Rows.Count).End(xlUp).Row 'the letter B is what the code looks at to choose the correct template. B must be changed in 3 places
Select Case UCase(Left(Cells(i, "B"), 100)) 'this number represent the amount of charactors in each case line. example ASSIGN VEHICLE ONLY is 19 charactors
Case "ASSIGN VEHICLE ONLY": p = "ASSIGN VEHICLE ONLY" 'This is one of 3 cases. the name just after the word CASE must match the template name.
Case "ASSIGN VEHICLE AND TITLE WORK": p = "ASSIGN VEHICLE AND TITLE WORK" 'You can create as many cases as you want
Case "DRIVER ADD": p = "DRIVER ADD"
Case "DISCONTINUE UNASSIGN": p = "DISCONTINUE UNASSIGN"
Case "DISCONTINUE TERM": p = "DISCONTINUE TERM"
Case "RENTAL UNIT WITH ENTERPRISE": p = "RENTAL UNIT WITH ENTERPRISE"
Case "DISCONTINUE MOVE TO STORAGE": p = "DISCONTINUE MOVE TO STORAGE"
Case "ASSIGN VEHICLE AND MOVE AND TITLE WORK": p = "ASSIGN VEHICLE AND MOVE AND TITLE WORK"
End Select
'Below is the location of all the templates. Add new templates to this locations if needed.
Set msg = objOL.CreateItemFromTemplate("\\fleet.ad\Data\Data1\VMSSHARE\Team GE Workflows\Work Flow Templates" & p & ".msg") 'the p represents the template name
If Err.Number > 0 Then MsgBox "No such template", vbCritical, Cells(i, "B") & "/Error #" & Err.Number 'warning box
'Below is the subject line. Each number represents columns, Example: 1 = column A.
msg.Subject = Cells(i, 2) & " Workflow# " & Cells(i, 1) & " Fleet/Unit " & _
Cells(i, 5) & " / " & Cells(i, 6)
msg.Attachments.Add ap & Cells(i, 1) & ".pdf" 'This looks at the WF number and attaches the WF based on Column A
msg.Send 'Send 'display Change this if you want to display email be its sent
Err.Clear
Next
Set msg = Nothing
Set objOL = Nothing
</code>
What i would like to add is the ability to add unique comments to each of these templates before they send and still keep what's already in the body of the template.
I know how to add "msg.Body = Cells(i, 3)" to this code but it overwrites what is already in the email template. I want to keep what's in there and add a unique comment at will.
Right now this macro looks at specific cells and grabs data from them. I can make column C be the comments column so it can be grabbed and added to the template Any idea how this can be done?
I have a macro that grabs a specific email template then attaches a specific PDF file to it then sends it all off without display.
Here's the code:
<code>
Dim objOL As Outlook.Application, msg As MailItem, p$, i%, ap$
'Below is the location of the all the workflows on the network
ap = "\\fleet.ad\Data\Data1\VMSSHARE\Team GE Workflows"
Set objOL = CreateObject("Outlook.Application")
On Error Resume Next
For i = 1 To Range("B" & Rows.Count).End(xlUp).Row 'the letter B is what the code looks at to choose the correct template. B must be changed in 3 places
Select Case UCase(Left(Cells(i, "B"), 100)) 'this number represent the amount of charactors in each case line. example ASSIGN VEHICLE ONLY is 19 charactors
Case "ASSIGN VEHICLE ONLY": p = "ASSIGN VEHICLE ONLY" 'This is one of 3 cases. the name just after the word CASE must match the template name.
Case "ASSIGN VEHICLE AND TITLE WORK": p = "ASSIGN VEHICLE AND TITLE WORK" 'You can create as many cases as you want
Case "DRIVER ADD": p = "DRIVER ADD"
Case "DISCONTINUE UNASSIGN": p = "DISCONTINUE UNASSIGN"
Case "DISCONTINUE TERM": p = "DISCONTINUE TERM"
Case "RENTAL UNIT WITH ENTERPRISE": p = "RENTAL UNIT WITH ENTERPRISE"
Case "DISCONTINUE MOVE TO STORAGE": p = "DISCONTINUE MOVE TO STORAGE"
Case "ASSIGN VEHICLE AND MOVE AND TITLE WORK": p = "ASSIGN VEHICLE AND MOVE AND TITLE WORK"
End Select
'Below is the location of all the templates. Add new templates to this locations if needed.
Set msg = objOL.CreateItemFromTemplate("\\fleet.ad\Data\Data1\VMSSHARE\Team GE Workflows\Work Flow Templates" & p & ".msg") 'the p represents the template name
If Err.Number > 0 Then MsgBox "No such template", vbCritical, Cells(i, "B") & "/Error #" & Err.Number 'warning box
'Below is the subject line. Each number represents columns, Example: 1 = column A.
msg.Subject = Cells(i, 2) & " Workflow# " & Cells(i, 1) & " Fleet/Unit " & _
Cells(i, 5) & " / " & Cells(i, 6)
msg.Attachments.Add ap & Cells(i, 1) & ".pdf" 'This looks at the WF number and attaches the WF based on Column A
msg.Send 'Send 'display Change this if you want to display email be its sent
Err.Clear
Next
Set msg = Nothing
Set objOL = Nothing
</code>
What i would like to add is the ability to add unique comments to each of these templates before they send and still keep what's already in the body of the template.
I know how to add "msg.Body = Cells(i, 3)" to this code but it overwrites what is already in the email template. I want to keep what's in there and add a unique comment at will.
Right now this macro looks at specific cells and grabs data from them. I can make column C be the comments column so it can be grabbed and added to the template Any idea how this can be done?