Reputation: 21
I have an order that comes in by email several times a week with an attachment that I need to send out to be processed. The software that processes the file requires that the email be free of signatures and text in the body.
I'm triggering the script via a rule that looks for the sender and an attachment. The script should grab a template and insert the attachment. The problem I'm having is inserting the attachment.
Here is what I have so far. Thanks for helping.
Sub SendLeadOrder(Item As Outlook.MailItem)
Set objMsg = Application.CreateItemFromTemplate("C:\OrderTemplate.oft")
objMsg.Attachments.Add Item.Attachments
objMsg.Display
'objMsg.Send
End Sub
Upvotes: 2
Views: 1305
Reputation: 33145
I'm pretty sure you'll need to save the attachments to disk then reapply them to the new message. Like this
Dim Item As Outlook.MailItem
Dim objMsg As Outlook.MailItem
Dim objAtt As Outlook.Attachment
Dim sPath As String
Set Item = ActiveInspector.currentItem
Set objMsg = Application.CreateItemFromTemplate("C:\OrderTemplate.oft")
For Each objAtt In Item.Attachments
sPath = Environ("TEMP") & "\" & objAtt.FileName
objAtt.SaveAsFile sPath
objMsg.Attachments.Add sPath
Next objAtt
objMsg.Display
Are you sure it's not easier to just forward the message and clean it up as necessary? Like this
Dim Item As Outlook.MailItem
Dim objMsg As Outlook.MailItem
Set Item = ActiveInspector.currentItem
Set objMsg = Item.Forward
With objMsg
.To = "[email protected]"
.Subject = "Predifined Subject"
.Body = vbNullString
.Display
End With
Upvotes: 2