Brenda Gorham
asked on
VBA script to change subject line to attachment name
We have a third party software where our scheduled reports are ran through to recipient's outlook email addresses.
Is there a way to setup a rule and have a script change the subject line to the attachment name on incoming emails? I do not need to save the attachment.
Any advice would be greatly appreciated.
Brenda
Is there a way to setup a rule and have a script change the subject line to the attachment name on incoming emails? I do not need to save the attachment.
Any advice would be greatly appreciated.
Brenda
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Did you select "run a script" action in your Outlook rule?
What you could do (with either code) would be add a message box when the code executes so you know it got to the VBA procedure. Try something like and then do a test receiving one of the emails you expect to trigger the rule that in turns runs the script, and see if you get a popup message box.
Sub AttachementSubject(MyMail As Outlook.MailItem)
MsgBox Now & " - Entered VBA code"
' Process this incoming Item
With Application.Session.GetItemFromID(MyMail.EntryID)
' Make sure it's a mail item
If .Class = olMail Then
' Only process if it has attachment(s)
If .Attachments.Count > 0 Then
' Change mail subject to attachment file name and save
.Subject = "[ATTACHMENT] " & .Attachments.Item(1).FileName
.Save
End If
End If
End With
End Sub
ASKER
Yes, I did.
ASKER
Thanks Bill! This is a great troubleshooting idea. I'll try that next.
ASKER
Alexei and Bill,
Even after adding the message box, I still could not get this to work. I think I may have uncovered the issue, however. Macros were not enabled in our Outlook. I am going to open a task with our corporate office, asking if I can enable these under the trust center.
Thank you both for all your help on this.
Brenda
Even after adding the message box, I still could not get this to work. I think I may have uncovered the issue, however. Macros were not enabled in our Outlook. I am going to open a task with our corporate office, asking if I can enable these under the trust center.
Thank you both for all your help on this.
Brenda
Answered.
ASKER
Neither of these have worked for me yet, but it could be I have it linked incorrectly. Bill, I do need the subject line to be the attachment name, before the user opens the email. I checked and we are not using conversation views.
Here are the steps I have taken on both of these:
Under the Visual Basic Editor, I added each version of the code: Next I created my rule:
When I ran / applied the rule, nothing changed. Keep in mind, we are receiving these emails from our Interbit product and the standard subject is hard coded within their product; "Report Distributed by Interbit Data..."
Please review the attached document. Do either of you see anything in my setup that would cause these not to work?
Very grateful,
Brenda
Doc1.docx