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.
Thread starter Similar threads Forum Replies Date
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
T Using A Rule To Forward An Email Containing Specific Word Using Outlook 5
D I would like to be able to Forward a Template to a specified email address on receiving an email in the Inbox. Using Outlook 1
L Automatically forward ALL outgoing/sent emails to another email adddress (not just for a specific distribution list) Using Outlook 2
T Exchange - forward email when user is not logged on Using Outlook 1
I Outlook 2007 Out of office Forward of email sent to a Distribution List member Using Outlook 1
O Can't send, reply, or forward email. Using Outlook 2
A Forward an entire email folder including the folder structure Using Outlook 2
P no text in forward email Using Outlook 2
A Outlook crashes and restart when I send, reply or forward an email Using Outlook 1
J Can not reply to or forward email from outlook but can send email started from new Using Outlook 1
O Email tool bar greyed out. Can't send or forward email. Using Outlook 1
R Exchange Powershell getting the forward email address for mailboxes Exchange Server Administration 2
A forward all email to another smtp server? Exchange Server Administration 5
B Outlook 2010 auto-forward deletes message text from forwarded email Using Outlook 7
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 2
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
Similar threads


















































Top