Outlook VBA - Automate Replies in Specific Folder - vba

First time poster and new to Outlook VBA.
I currently have a rule that moves all incoming mail that contains the string “Apple” in the body to a specific folder.
I ultimately want this:
On any new email that gets moved to that folder, if the body does NOT contain the word “fruit” then reply with “Deny”, a line break and then a couple sentences. The original subject and body should remain. It would act the same as if I hit the “Reply” button.
I’m getting stuck here, thank you!

Related

Get selected text from subject line

I have searched and found this answer but it won't seem to work for me. I need to get the selected (highlighted) text from the subject of the email. When I try the linked solution from either the preview pane or from an open email, I only get the first character of the body. I attempted to look at all properties of mail.GetInspector.WordEditor but nothing seems to contain the selected text. As stated, mail.GetInspector.WordEditor.Application.Selection only has the first character of the body. In my code, I have mail as type MailItem and is set to ActiveExplorer.Selection.Item(1).
My code works fine when the selected text is in the body of the email.
You need to find the Windows control containing the subject and send WM_GETTEXT message to it.
I don't think you can do that in VBA.

Copy content from table in a mail to another mail using VBA in outlook?

I am trying to get started with VBA in outlook and I was wondering if anyone had code that copied and pasted the content of one cell from a table in an outlook mail to another mail (only the content - not the cell or table)?
A small piece of example code would be great.
Best regards
It looks like you need to parse the message body and find the required value. Then paste it to another message body.
The Outlook object model provides three main ways for working with item bodies:
Body.
HTMLBody.
The Word editor. The WordEditor property of the Inspector class returns an instance of the Word Document which represents the message body. So, you can use the Word object model do whatever you need with the message body.
See Chapter 17: Working with Item Bodies for more information.
Also you may find the Getting Started with VBA in Outlook 2010 article helpful.

Macro/Script - Set Forward Blue Line as Reference to delete previous emails when forwarding without manually deleting the previous emails

Seeking your insight on this process:
I want to forward the latest email received only not including the entire thread of the emails. Can I forward that email without manually deleting the previous emails on the thread?
I want to automatically send the NEWEST/LATEST emails received to a specific email address without the previous emails on the thread.
What I'm thinking is, I will set the "BLUE LINE" as reference, for starting position and ending position. Because as we all know, whenever we forward a HTML email, there's a blue line separating emails received.
Is it possible to do that? Set blue line as reference, then delete everything not inside the lines.
You can edit the message body at runtime using VBA macros. The Outlook object model provides three main ways for working item bodies:
Body - a string representing the clear-text body of the Outlook item.
HTMLBody - a string representing the HTML body of the specified item.
Word editor - the Microsoft Word Document Object Model of the message being displayed. The WordEditor property of the Inspector class returns an instance of the Document class from the Word object model which you can use to set up the message body.
You can read more about all these ways in the Chapter 17: Working with Item Bodies. It us up to you which way is to choose to customize the message body.
If you are new to VBA macros, see Getting Started with VBA in Outlook 2010.

Change hyperlink based on date in Outlook 2013

Every day our Helpdesk has to send out a report. That report needs to link to a website that displays that days statistics.
Example URL:
http://hostname/dashboardname/date
Which would look like this:
http://hostname/HelpdeskTickets/2015-03-18
Heres what I've tried:
First I looked into field code values and doing something like this
{HYPERLINK "http://hostname/HelpdeskTickets/{DATE \# "yyyy-MM-dd"}"}
And this works, until you close the outlook message. If you don't have F9 to update the field code, and save and close the .msg file it will disappear leaving just the blank link without a date. If you hit F9 before closing it, it puts that days date into the field, however when you close and save it the field code disappears and leaves the date in place of the date field code. Also I noticed this problem doesn't happen in word. You can save and close a word file and it keeps the field codes.
Another thing I've tried is to use VBA to edit the links in the message body. So far nothing has actually worked.
The only thing that partially worked was taking the body of the document and using a string replace function on it. However this destroys all formatting and hyperlinks along with it.
I'm open to any ideas on how this can be achieved.
My main problem is that the people at the helpdesk can't seem to use anything that isn't fool proof. So having them press F9 before sending this email was actually scaring people that they wouldn't be able to do that.
You can use VBA to edit the message body programmatically. It is not clear what code you used earlier, but the main ways are described below:
HTMLBody - a string representing the HTML body of the specified item. The HTMLBody property should be an HTML syntax string.
The Word editor. The WordEditor property of the Inspector class returns an instance of the Document class from the Word object model. So, the message body is represented by the Word Document.
You can read more about all possible ways in the Chapter 17: Working with Item Bodies.

Outlook: How to refresh folder after setting "Categories" on mails

I wrote some code to parse the subjects of mails in a certain folder. The parsed stuff gets written to the Categories-field of the mail-object. According to debugging this works nicely.
The problem now is that I do not see the effect in Outlook. Actually I only see it in five out of ~30 mails. On those five the Categories-column and the output in the mail panel present the correct value. All other mails show nothing in those two areas.
Clicking on each mail, going to another folder and then back, double-clicking a mail don't do anything.
What do I need to do to update the folder to see the categories on all mails?
EDIT:
I wrote some more code that only picks the currently selected mails. This code only works if one mail is selected even though the loop touches all mails. If I select more than one mail only the first selected mail may (yes, may) have changed.
While looking for something else I ran into another Outlook-question and had an enlightening moment. The code sample there includes the line
Item.Save
which I had not in my code. I added the line after all manipulations on the mail-item and now it works flawlessly. It even works with many mails selected.
Some solutions are quite simple...