My company uses an ERP system that emails our customers their invoices as attachments. For whatever reason, these emails from the ERP system are not delivered to Gmail or Yahoo email accounts, but we have included ourselves as recipients and get it without issue. From there we can Reply All, include the Attachment, and our customers receive their invoices. This is an entirely manual process right now. To get around this, I am trying to create a rule that when we receive the emails, the ReplyAll with Attachments occurs automatically.
I thought I had it with the VBA code below, but it when it is triggered by the rule, it Replies All with Attachment based on the email I have selected in Outlook and the time the rule is triggered, and not based on the email that triggers the rule. Please help me out. I am an accountant not a programmer.
I thought I had it with the VBA code below, but it when it is triggered by the rule, it Replies All with Attachment based on the email I have selected in Outlook and the time the rule is triggered, and not based on the email that triggers the rule. Please help me out. I am an accountant not a programmer.
Code:
Sub ReplyAllWithAttachments(Item As Outlook.MailItem)
'ReplyAllWithAttachments
Dim oReply As Outlook.MailItem
Dim oItem As Object
Set oItem = GetCurrentItem()
If Not oItem Is Nothing Then
Set oReply = oItem.ReplyAll
CopyAttachments oItem, oReply
oReply.Display
oReply.Send
End If
Set oReply = Nothing
Set oItem = Nothing
End Sub
Function GetCurrentItem() As Object
On Error Resume Next
Select Case TypeName(Application.ActiveWindow)
Case "Explorer"
Set GetCurrentItem = Application.ActiveExplorer.Selection.Item(1)
Case "Inspector"
Set GetCurrentItem = Application.ActiveInspector.CurrentItem
End Select
End Function
Sub CopyAttachments(oSourceItem, oTargetItem)
Set oFso = CreateObject("Scripting.FileSystemObject")
Set fldTemp = oFso.GetSpecialFolder(2) 'Temporary Folder
sPath = fldTemp.Path & "\"
For Each oAtt In oSourceItem.Attachments
sFile = sPath & oAtt.FileName
oAtt.SaveAsFile sFile
oTargetItem.Attachments.Add sFile, , , oAtt.DisplayName
oFso.DeleteFile sFile
Next
Set fldTemp = Nothing
Set oFso = Nothing
End Sub