VBA Script to Open highlighted e-mail and Edit Message

Status
Not open for further replies.

NickO

New Member
Outlook version
Outlook 2016 64 bit
Email Account
POP3
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
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
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!
 

Dan_W

Member
Outlook version
Outlook 2016 32 bit
Email Account
Outlook.com (as MS Exchange)
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
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!
 

Dan_W

Member
Outlook version
Outlook 2016 32 bit
Email Account
Outlook.com (as MS Exchange)
You're very welcome. I'm glad I was able to to help (and, more importantly, that it actually worked)!
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
J Outlook Rules VBA Run a Script - Multiple Rules Outlook VBA and Custom Forms 0
FryW Need help modifying a VBA script for in coming emails to auto set custom reminder time Outlook VBA and Custom Forms 0
A VBA Script - Print Date between first email in Category X and last email in Category Y Outlook VBA and Custom Forms 3
L Modifying VBA script to delay running macro Outlook VBA and Custom Forms 3
L Need help modifying a VBA script for emails stuck in Outbox Outlook VBA and Custom Forms 6
D.Moore VBA script fail after Office 365 update Using Outlook 8
S Change VBA script to send HTML email instead of text Outlook VBA and Custom Forms 3
dweller Outlook 2010 Rule Ignores VBA Script Outlook VBA and Custom Forms 2
K Outlook Archive to PST Files by Date Range VBA Script? Outlook VBA and Custom Forms 1
Peter H Williams Enable script containing VBA Outlook VBA and Custom Forms 12
R VBA Script Quick Parts Using Outlook 1
Q VBA Script to move item in secondary mailbox Outlook VBA and Custom Forms 2
N VBA Script to Send Automatic Emails from Outlook 2010 Outlook VBA and Custom Forms 1
O modify vba to run it as script rule Outlook VBA and Custom Forms 8
P How many subs can run in one outlook VBA script Using Outlook 5
J Email Parsing VBA Script for Outlook - NEEDED Outlook VBA and Custom Forms 7
P Vba script including macro appears in rules but wont run Outlook VBA and Custom Forms 6
R Adding vba to script list Outlook VBA and Custom Forms 4
F VBA script to highlight specific words Outlook VBA and Custom Forms 1
D VBA Script to extract text matching specific criteria Outlook VBA and Custom Forms 1
D VBA Script (Ask to where to save send mail) Outlook VBA and Custom Forms 1
M VBA script to allow mail merges of distribution groups? Using Outlook 7
D VBA script to auto download attachments and rename file according to subject line Outlook VBA and Custom Forms 23
Hudas Outlook VBA script reverting back to previous changes Outlook VBA and Custom Forms 2
J Outlook 2007 Rules & VBA: How to run a script on a report message (ReportItem) Using Outlook 14
V "Accept + Send the Response now", VBA script? Using Outlook 1
R Addins4Outlook TagIt! addin script or VBA module? Using Outlook 2
S Outlook VBA rule script to process both MailItem and MeetingItem Using Outlook 0
A VBA Script to Forward Spam to AntiSpam Provider Using "Blank" Form Outlook VBA and Custom Forms 2
L Limit VBA Script to one Outlook account Using Outlook 1
K vba code to auto download email into a specific folder in local hard disk as and when any new email arrives in Inbox/subfolder Outlook VBA and Custom Forms 0
D VBA - unable to set rule condition 'on this computer only' Outlook VBA and Custom Forms 3
L Fetch, edit and forward an email with VBA outlook Outlook VBA and Custom Forms 2
BartH VBA no longer working in Outlook Outlook VBA and Custom Forms 1
W Can vba(for outlook) do these 2 things or not? Outlook VBA and Custom Forms 2
MattC Changing the font of an email with VBA Outlook VBA and Custom Forms 0
P MailItem.To Property with VBA not work Outlook VBA and Custom Forms 2
P Tweak vba so it can target another mailbox Outlook VBA and Custom Forms 1
A Outlook 2010 VBA fails to launch Outlook VBA and Custom Forms 2
richardwing Outlook 365 VBA to access "Other Actions" menu for incoming emails in outlook Outlook VBA and Custom Forms 0
W Create a Quick Step or VBA to SAVE AS PDF in G:|Data|Client File Outlook VBA and Custom Forms 1
C Outlook (desktop app for Microsoft365) restarts every time I save my VBA? Using Outlook 1
D VBA Macro to Print and Save email to network location Outlook VBA and Custom Forms 1
TedSch Small vba to kill political email Outlook VBA and Custom Forms 3
E Outlook 365 Outlook/VBA Outlook VBA and Custom Forms 11
N VBA Macro To Save Emails Outlook VBA and Custom Forms 1
Z VBA Forward vs manual forward Outlook VBA and Custom Forms 2
J VBA Cannot programmatically input or change Value for User Defined field Using Outlook 1
J VBA for outlook to compare and sync between calendar Outlook VBA and Custom Forms 1
A Any way to force sort by/group by on search results with VBA? Outlook VBA and Custom Forms 1

Similar threads

Top