Get selected text from subject line - vba

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.

Related

Outlook VBA - Automate Replies in Specific Folder

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!

VSTO Outlook Plugin updates Appointment.Body and thus Outlook shows text instead of html part of multipart message

I receive multipart invitations which include calendar and text and html part. When I open those invitation mails in outlook it shows the html part.
Now my code updates the text part with:
myAppointment.Body = myAppointment.Body.Replace(OutlookAddIn4.Resources.Resources.LinkToMeeting + " " + meetingLink, "");
myAppointment.Save();
This text is normally NOT included in the text part. Therefore this call DOES NOT change anything.
Although Outlook now shows the text part instead of the HTML part.
My questions:
1.) How can avoid this?
2.) Is there a chance to determine in my Plugin whether Outlook shows the html part (RTFBody that is, right) or the text part?
Thanks
Hannes
Firstly, before unconditionally resetting the body, check if there is something to replace and only then do anything.
Secondly, you can take a look at the RtfBody property and set it instead. If HTML is used, RTF will have the "\fromhtml" header. Latest versions of Outlook support HTML, but HTMLBody property has not been added to the AppointmentItem object. In theory, you can set the PR_HTML property, but PropertyAccessor.SetProperty won't let you set it. If using Redemption is an option (I am its author), you can either set the RDOAppointment.HTMLBody property or set PR_HTML.

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.

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.

Using VSTO to perform an action via selected e-mail text in Outlook

This should be pretty a pretty common scenario, but I have not found a solution yet.
I would like to highlight some text within the body of an e-mail and then click on something (context menu, toolbar button, etc) to perform a URL navigation using the selected text. For example, highlight the Fex Ex tracking number and then navigate to their web site using it as a query parameter (like "ww.fedextracking.com?packageid=12345").
How can you capture the selected text within an e-mail and then perform an action? I would greatly appreciate any suggestions or examples.
Thank you!
For Outlook 2007-2010 (or previous versions using WordMail), you can retrieve a Word object from the Inspector.WordEditor property. Then you can work with Word.Selection to access the selected text.
However, for Plain Text or Rich Text scenarios with Outlook 2000-2003, you have to use the SafeInspector object with Redemption (http://www.dimastr.com/redemption/) to access the selected text. I can't remember, but for HTML format messages with Outlook 2003-2003 you may be able to access the selected text with the IHTMLDocument object retrieved from SafeInspector.
I appreciate it's 588 days since you asked your question Loki70, but if somebody else Googles up this page (like I did, looking for how to create a selected text right-click context menu entry) then this may be an answer for you.
I have been using AutoHotKey, which works not just in Outlook, but everywhere in Windows, and have been writing utilities to Google the selected text, open an SSH session in PuTTY to the selected hostname, and similar.
If you don't mind running an extra application on your PC to capture the hotkey combination that you send, then this would do exactly what you're asking.
Here is my post on the AutoHotKey forum with a link to my code:
http://www.autohotkey.com/community/viewtopic.php?t=86402
It would be trivial to adapt this to do the FedEx query you've mentioned.
I hope this helps.