forward email with attachment using .oft

Status
Not open for further replies.

dwebbcw

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
I have no experience but I've cannibalized/pieced together a vba Outlook macro that calls an outlook .oft template. The end result is that the user is prompted for entries like firstname, lastname, etc. which are added into the body of the email along with some static text. My end users are receiving an email from the scanner with a pdf attached. Rather than activating the macro (below) which creates a new email which they have to drag the pdf into, I would like them to be able to just run the macro directly on the email from the scanner so they don't have to bother finding the first email and dragging the pdf over to the new email.

How can I get this macro to forward an existing email rather than creating a new one?

Sub Statement_Email()
Dim myItem As Outlook.MailItem
Dim strRecipient As String
Dim strStatementMonth As String
Dim strThroughDate As String
Dim strHTML As String


Set myItem = Application.CreateItemFromTemplate("C:\Users\username\AppData\Roaming\Microsoft\Templates\Statement.oft")
strHTML = myItem.HTMLBody

strLastName = InputBox("Recipients Last Name?")
strFirstName = InputBox("Recipients First Name?")
strPrefix = InputBox("Recipients Prefix (ex. Mr., Ms., Dr.)?")
strMatterID = InputBox("Matter Number?")
strStatementMonth = InputBox("What is the statement date?")
strThroughDate = InputBox("Services rendered through what date?")

myItem.HTMLBody = Replace(myItem.HTMLBody, "%STATEMENTMONTH%", strStatementMonth)
myItem.HTMLBody = Replace(myItem.HTMLBody, "%THROUGHDATE%", strThroughDate)
myItem.HTMLBody = Replace(myItem.HTMLBody, "%RECIPIENT%", strRecipient)
myItem.HTMLBody = Replace(myItem.HTMLBody, "%PREFIX%", strPrefix)
myItem.HTMLBody = Replace(myItem.HTMLBody, "%LASTNAME%", strLastName)
myItem.Subject = Replace(myItem.Subject, "%LASTNAME%", strLastName)
myItem.Subject = Replace(myItem.Subject, "%FIRSTNAME%", strFirstName)
myItem.Subject = Replace(myItem.Subject, "%MATTERID%", strMatterID)
myItem.Display

End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
This line: Set myItem = Application.CreateItemFromTemplate("C:\Users\username\AppData\Roaming\Microsoft\Templates\Statement.oft")

control what happens.

Assuming the message is selected, not open on screen, use
Dim oItem As Outlook.MailItem
Set oItem= Session.ActiveExplorer.Selection.Item(1)
set myitem = oitem.forward
 

dwebbcw

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Thank you Diane.

I added those lines but am still having a problem. When the email with the attachment is highlighted in my inbox I click the quick launch icon to run the macro. I get an error that reads:
Run-time error '438': Object doesn't support this property or method.

Maybe I didn't add your lines correctly, this is what the entire macro looks like now:

Sub Forward_Statement2()
Dim myItem As Outlook.MailItem
Dim strRecipient As String
Dim strStatementMonth As String
Dim strThroughDate As String
Dim strHTML As String

Dim oItem As Outlook.MailItem

Set myItem = Application.CreateItemFromTemplate("C:\Users\username\AppData\Roaming\Microsoft\Templates\Statement.oft")
strHTML = myItem.HTMLBody
Set oItem = Session.ActiveExplorer.Selection.Item(1)
Set myItem = oItem.Forward

strLastName = InputBox("Recipients Last Name?")
strFirstName = InputBox("Recipients First Name?")
strPrefix = InputBox("Recipients Prefix (ex. Mr., Ms., Dr.)?")
strMatterID = InputBox("Matter Number?")
strStatementMonth = InputBox("What is the statement date?")
strThroughDate = InputBox("Services rendered through what date?")

myItem.HTMLBody = Replace(myItem.HTMLBody, "%STATEMENTMONTH%", strStatementMonth)
myItem.HTMLBody = Replace(myItem.HTMLBody, "%THROUGHDATE%", strThroughDate)
myItem.HTMLBody = Replace(myItem.HTMLBody, "%RECIPIENT%", strRecipient)
myItem.HTMLBody = Replace(myItem.HTMLBody, "%PREFIX%", strPrefix)
myItem.HTMLBody = Replace(myItem.HTMLBody, "%LASTNAME%", strLastName)
myItem.Subject = Replace(myItem.Subject, "%LASTNAME%", strLastName)
myItem.Subject = Replace(myItem.Subject, "%FIRSTNAME%", strFirstName)
myItem.Subject = Replace(myItem.Subject, "%MATTERID%", strMatterID)
myItem.Display

End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Besides the typo in my last post (now fixed) - the top part of the macro is below. oItem is the original message, myitem is the forward.

Code:
Sub Forward_Statement2()
Dim myItem As Outlook.MailItem
Dim oItem As Outlook.MailItem
Dim strRecipient As String
Dim strStatementMonth As String
Dim strThroughDate As String
Dim strHTML As String

Set oItem = Application.ActiveExplorer.Selection.Item(1)
Set myItem = oItem.Forward
strHTML = oItem.HTMLBody
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
G Forward email body to other mail list directly from Exchange server Exchange Server Administration 1
D auto forward base on email address in body email Outlook VBA and Custom Forms 0
Bering Forward selected email without the original email appended Outlook VBA and Custom Forms 0
J Automatically forward email and apply template Outlook VBA and Custom Forms 0
O Forward a email with modified body Automatically. Outlook VBA and Custom Forms 0
C How to rename subject line and forward the email Outlook VBA and Custom Forms 2
R Error when trying to forward current email item Outlook VBA and Custom Forms 7
B Forward every other email in Outlook 2013 Outlook VBA and Custom Forms 2
D Disable or hide "reply" and "reply to all" and "forward" in email from access vba Outlook VBA and Custom Forms 1
Sabastian Samuel HOW DO I FORWARD AN EMAIL WITH MACRO using an email that in the body of another email Outlook VBA and Custom Forms 3
A Forward Outlook Email by Filtering using Macro Rule Outlook VBA and Custom Forms 44
Brostin Forward a mail to the address listed in the email text Outlook VBA and Custom Forms 1
A Creating an outlook rule to forward an email with a specific message Using Outlook 1
D How to forward each email x minutes after it arrives in inbox and hasn't been moved or deleted? Using Outlook 1
W Macro to forward email Outlook VBA and Custom Forms 2
mikecox Forward email to another address; not with Rules Using Outlook 3
divan Macro to format email in a certain folder then forward to email address Using Outlook 3
R Auto-create receipt from email and forward to payer Using Outlook 3
C Unable to forward email with URL Using Outlook 2
M rule to change subject, pull email addresses from body, and forward with templ Using Outlook 14
S Rule to Auto-forward/re-direct a specific incoming email to a group via BCC? Using Outlook 1
A Outlook 2010 - Want to Have All Email Reply Forward as Rich Test Using Outlook 7
P email arrows - respond and forward Using Outlook 1
L Forward Email and Insert Sender's Email address in body Outlook VBA and Custom Forms 3
M Forward email as insert from button Outlook VBA and Custom Forms 1
J Rule to Forward email but delay delivery 10 minutes Outlook VBA and Custom Forms 2
S forward email Outlook VBA and Custom Forms 1
C UDFs Reply vs Forward Outlook VBA and Custom Forms 3
M In Outlook Calendar remove the buttons: 'Today' and '<' (Back a day) and '>' (Forward a day) that are below the Ribbon and above the calendar display. Using Outlook 0
M Outlook macro to automate search and forward process Outlook VBA and Custom Forms 6
G Missing forward/replied icons Using Outlook 2
M VBA to auto forward message with new subject and body text Outlook VBA and Custom Forms 8
B Automatically Forward Emails and Remove/Replace All or Part of Body Outlook VBA and Custom Forms 8
M Forward Appointment as BCC with VBScript Outlook VBA and Custom Forms 7
C Don't forward duplicate Using Outlook 0
undercover_smother Automatically Forward All Sent Mail and Delete After Send Outlook VBA and Custom Forms 10
I change subject and forward without FW: Outlook VBA and Custom Forms 4
C VBA to Forward e-mails from certain address and between certain times Outlook VBA and Custom Forms 1
J Forward Action in Form Outlook VBA and Custom Forms 1
J Auto Forward - Include Attachment and change Subject depending on original sender Outlook VBA and Custom Forms 3
K add pdf to every reply or forward Outlook VBA and Custom Forms 1
N Going Forward: Using Outlook 2016 for RSS Feeds Using Outlook 2
J Forward Message after editing attachments and include edited attachments Using Outlook 5
R changing FW: on forward Outlook VBA and Custom Forms 3
Z Auto Forward Using Outlook 4
N Outlook script to forward emails based on senders' address Outlook VBA and Custom Forms 2
S Merge Emails with attachments with inbox rule to forward Using Outlook 5
B Auto Save of Attachments from Multiple Emails and forward attachments to user group Outlook VBA and Custom Forms 1
D Forward message to address from subject Outlook VBA and Custom Forms 1
J How to change From then forward message Outlook VBA and Custom Forms 1

Similar threads

Top