VBA Script to Open highlighted e-mail and Edit Message

NickO

New Member
Outlook version
Outlook 2016 64 bit
Email Account
POP3
#1
Hello,

I am trying to create a script that will open a highlighted e-mail and allow me to use the "Actions", "Edit Message" function to type "Done and Today's date" is sounds simple to me but I have been unable to find anything. Maybe my searching is really bad ;). Any and all help would be great! Thanks.
 

NickO

New Member
Outlook version
Outlook 2016 64 bit
Email Account
POP3
#2
The process we are going through is the following: an e-mail is sent to an inbox with a needed journal entry to be input. Once the journal entry has been completed we open the e-mail, use actions, select edit message, and type "Done and Today's date".

Here is the action I am trying to perform.
1536249236233.png


If more information is needed, please let me know. I am trying to do all of this in Outlook 2016.

Thank you!
 

NickO

New Member
Outlook version
Outlook 2016 64 bit
Email Account
POP3
#3
Does anyone know a script that will open the current selected e-mail? Just trying to get a start on this as I cannot find anything.

Thanks!
 
Outlook version
Outlook 2016 32 bit
Email Account
Outlook.com (as MS Exchange)
#4
Hi NickO

In terms of the first part of your question (how to work with the selected outlook mailitem), the best function I've come across is actually available on the Slipstick blog: GetCurrentItem

Code:
Function GetCurrentItem() As Object
    Dim objApp As Outlook.Application
       
    Set objApp = Application
    On Error Resume Next

    Select Case TypeName(objApp.ActiveWindow)
        Case "Explorer"
            Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1)
        Case "Inspector"
            Set GetCurrentItem = objApp.ActiveInspector.CurrentItem
    End Select
    
    Set objApp = Nothing
End Function
As for the second part of your question, where in the email were you hoping to have that written? If, for example, you wanted to add the following text - "[DONE - 21-05-2018]" - in front of the existing subject of the email, you could use the following code:

Code:
Sub EditMyMessage()
    Dim objItem As Object
    Set objItem = GetCurrentItem

    If objItem.Class = olMail Then
        objItem.Subject = "[DONE - " & Format(Now, "dd-mm-yyyy") & "] " & objItem.Subject
        objItem.Save
    Else
        'Do something
    End If

    Set objItem = Nothing
End Sub
NB: please note that this subroutine will save the changes to the email automatically, so you should do some trial-and-error on sample emails to make sure it is working correctly.

I hope that helps.

Dan
 

NickO

New Member
Outlook version
Outlook 2016 64 bit
Email Account
POP3
#5
Sorry it took me so long to get back to you Dan. I have been trying the code off an on and I finally got it put into the correct order and it is working beautifully! Thank you so much! I have moved the "edited comment" to the body of the e-mail, but the original code you put together is great, thank you so much!
 
Outlook version
Outlook 2016 32 bit
Email Account
Outlook.com (as MS Exchange)
#6
You're very welcome. I'm glad I was able to to help (and, more importantly, that it actually worked)!
 

Similar threads

Top