Record opened emails for reopening later

Status
Not open for further replies.

Alan Grant

Member
Outlook version
Outlook 2016 64 bit
Email Account
Exchange Server 2013
I'd like to have a macro button on the ribbon that will export the Subject name and Received date/time of all opened Inbox email messages to a list (Excel or CSV), and a second macro button on the ribbon that will refer to that list and reopen those emails. If this is possible, please give me an idea of how I could code this. Thanks.
 
The first one is definitely easy - i have macro samples that come close and would need tweaking. The message id needs saved so it can find the correct message later.

The second one might work best as an excel macro - i don't think i have any samples for that.
 
Hi Diane. If I can get away with even the first part only I would be happy, as I could then have a log of previously opened emails that I can open each manually. That's the most important part for me. From your code sample it looks like it is based on selected emails (Selection property) vs opened emails. So if I read that right, how can I enumerate opened emails? Is there a property, function, or method for that? Regards.
 
that would be the read state. do you want it to run automatically when you mark a message read or just run daily or on a schedule?
 
The scenario I wish to cover is when I inadvertently close Outlook or my pc crashes while I have a number of emails open as reminder to respond to, so by having this macro I'm asking about I could run it which will record the subject names of the opened emails into a file or spreadsheet. It's really just a safety precaution so I could more easily know what I had open.
 
I'm really not experienced with VBA but after some more reading I thought of another option I think might accomplish my goal more easily: for each Inbox email that I open a copy is automatically (not explicitly executed) inserted into a new Outlook folder called "Opened Emails". When I close the Inbox email, its copy is deleted from the "Opened Emails" folder. Think this is doable?
 
No, i don't think its workable but i will sleep on it. Flagging would be easier - at last if you aren't flagging messages for reminders. it would be easy to do too - hit the flag when you open it and click again when you close.

Categories would work too, but with the quick click gone in the compact view, itsan extra click or you need o use a keyboard shortcut.
 
Sure, categories would be fine I think, if it could be automatically made to be (eg) Yellow when open but uncategorized upon being explicitly closed by me.

*I just need to way to know what emails I had open if Outlook was inadvertently closed, or the computer did a scheduled reboot, crashed, or Outlook crashed.* That's really my main goal. Thanks.
 
By the way, is the difficulty in trying to do this due to Outlook's inability to process such VBA code in the background (vs via a macro button)?
 
Outlook can handle background processing, but it can get complicated, especially with multiple messages open.

While I put on my thinking cap :) try always opening outlook using the /restore switch. This will reopen windows and messages, but I'm not sure if it always remembers the last open messages.
 
Ok thanks.

By the way, I have tried the /restore switch a few times but find it often doesn't work in these situations for some reason.

For my learning, does background VBA still go under ThisOutlookSession as an event procedure?
 
By the way, I have tried the /restore switch a few times but find it often doesn't work in these situations for some reason.
I'm guessing it doesnt record all of the open messages, except under specific circumstances, such as windows rebooting.

VBA that runs automatically needs to be in ThisOutlookSession. We can look for open events and close events, but it can get messy - and trying ot do a lookup at the same time can be difficult. I think categories (or flags) might be more efficient and less prone to error.
 
baby steps... this sets the category. i'm still working on removing it on close.

Private WithEvents m_Inspectors As Outlook.Inspectors
Private WithEvents m_Inspector As Outlook.Inspector

Private Sub Application_Startup()
Set m_Inspectors = Application.Inspectors
End Sub
Private Sub Initialize_Handler()
Set myItem = Application.ActiveInspector.CurrentItem
End Sub


Private Sub m_Inspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
If TypeOf Inspector.CurrentItem Is Outlook.MailItem Then
'Handle emails only
Set m_Inspector = Inspector
End If
End Sub

Private Sub m_Inspector_Activate()
Dim Mail As Outlook.MailItem
Set Mail = m_Inspector.CurrentItem
If Len(Mail.EntryID) > 0 Then
'Edit the subject only for new emails
Mail.Categories = "Opened"
Mail.Save
End If
Set m_Inspector = Nothing
End Sub
 
This looks very promising. I will try out what you have so far.

FYI, if this works out, there's a lot of people who have asked the question "Can Outlook record/remember opened emails on demand?" or "Are there 3rd party utilities that do similar?" (Stardock came close with their Groupy product but they said they cannot read opened emails yet for this specific purpose).

Maybe you could make some beer $$ with this lol.
 
i think I got it working, using Michael's code - Inspector Wrapper: Receive Events of Multiple Emails - VBOffice

This Outlook Session:
Private WithEvents m_Inspectors As Outlook.Inspectors
Private m_MyInspectors As VBA.Collection
Private m_lNextKey As Long

Private Sub Application_Startup()
Set m_Inspectors = Application.Inspectors
Set m_MyInspectors = New VBA.Collection
End Sub

Private Sub m_Inspectors_NewInspector(ByVal Inspector As Outlook.Inspector)
On Error Resume Next
Dim oInspector As cInspector

Set oInspector = New cInspector

If TypeOf Inspector.CurrentItem Is Outlook.MailItem Then
'Handle emails only
Set m_Inspector = Inspector

Dim Mail As Outlook.MailItem
Set Mail = m_Inspector.CurrentItem
If Len(Mail.EntryID) > 0 Then
Mail.Categories = "Opened"
Mail.Save
End If

If oInspector.Init(Inspector, CStr(m_lNextKey)) Then
m_MyInspectors.Add oInspector, CStr(m_lNextKey)
m_lNextKey = m_lNextKey + 1
End If
End If

End Sub

Friend Property Get MyInspectors() As VBA.Collection
Set MyInspectors = m_MyInspectors
End Property
Private Sub m_Mail_Close(Cancel As Boolean)
CloseInspector
End Sub


A class module named cInspector
Private WithEvents m_Inspector As Outlook.Inspector
Private WithEvents m_Mail As Outlook.MailItem
Private m_IsClosed As Boolean
Private m_sKey As String

Friend Function Init(oInspector As Outlook.Inspector, _
sKey As String _
) As Boolean
Dim obj As Object

If Not oInspector Is Nothing Then
Set obj = oInspector.CurrentItem
If TypeOf obj Is Outlook.MailItem Then
Set m_Mail = obj
Set m_Inspector = oInspector
m_sKey = sKey
Init = True
End If
End If
End Function

Private Sub m_Inspector_Close()
CloseInspector
End Sub

Private Sub Class_Terminate()
CloseInspector
End Sub

Friend Sub CloseInspector()
On Error Resume Next
If m_IsClosed = False Then
m_IsClosed = True
ThisOutlookSession.MyInspectors.Remove m_sKey
m_Mail.Categories = ""
m_Mail.Save
Set m_Mail = Nothing
Set m_Inspector = Nothing
End If
End Sub
 
Hi Diane.

I pasted the new code into my ThisOutlookSession and upon reopening Outlook it threw an error. Reopened it again and this time hangs on opening, doesn't give me a chance to remove any code etc. Doesn't seem to be a bypass key to suppress macros on opening. Tried Run Outlook /Safe and that goes a little further then hangs. Do you know of any way to bypass the macros on opening or otherwise reset Outlook?

By the way it may have nothing to do with the above macro and I assume full responsibility of course. I'm still very optimistic about it.

Thanks!
 
go to %appdata%\microsoft\outlook and rename the otm file - outlook will create a clean new one.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
A Record opened emails for reopening later Using Outlook 2
B Track Record Activity Using Outlook 1
D Record Appointment to Calendar on "Public Folder" Outlook VBA and Custom Forms 13
B Customize contact record phone fields Using Outlook 2
B Macro to record what time it is Outlook VBA and Custom Forms 2
N linking an already sent/rec'd email to contact record like it did in 2000 Using Outlook 0
M convert/import a customized record into the default "Account" record BCM (Business Contact Manager) 0
P People/Contact Record gets deleted when I edit it? Using Outlook 3
S Editing an email with notes and saving it for record using Macro Outlook VBA and Custom Forms 3
U No scrolling in note field of contact record Using Outlook 1
R Can BCM monitor and select specific emails and use content info to update the client's record? BCM (Business Contact Manager) 1
M Predefined Outlook Fields not available to add into a BCM record BCM (Business Contact Manager) 0
J How to show the "value" of a user-defined Account field in a Contact Record BCM (Business Contact Manager) 2
J How to create fields that will use the same value on different record types BCM (Business Contact Manager) 2
A delete database --> record remnants ?? BCM (Business Contact Manager) 3
M BCM 2010 Link to Record (very) slow BCM (Business Contact Manager) 2
L Importing multiple record from .vcf (vCard) file Using Outlook 5
P Hyperlink to Access record/Form Outlook VBA and Custom Forms 2
H Re: record of sales for each contact BCM (Business Contact Manager) 1
A Is There An Easier Way to Access a Business Contact Record? BCM (Business Contact Manager) 2
A Programmatically duplicating BCM's "Link to Record" function BCM (Business Contact Manager) 2
C Outlook record the step I take getting to the user template? Outlook VBA and Custom Forms 1
S Record eMail details in Outlook 2007 Outlook VBA and Custom Forms 5
R One Click business contact record creation - From an E Mail? BCM (Business Contact Manager) 1
Y How to record macros in Outlook2007? Outlook VBA and Custom Forms 1
U When opening shared Calendar "The set of folders cannot be opened" Using Outlook 0
T Outlook365 search item listed as "potential matches" can't be opened Using Outlook 0
V Outlook macros no longer run until VB editor is opened Outlook VBA and Custom Forms 0
O Cannot expand the folder. The set of folders cannot be opened. You do not have permission to log on. Using Outlook 1
M Outlook 2013 Script Assistance - Save Opened Link with Subject Added Outlook VBA and Custom Forms 1
C Outlook (365) is crashing as soon as its opened Using Outlook 2
rino email campaign - tracking opened emails Outlook VBA and Custom Forms 6
N Paste content to Excel when .txt file (attachment) is opened Outlook VBA and Custom Forms 1
Diane Poremsky The custom form cannot be opened. Outlook will use an Outlook form instead. Using Outlook 0
I Identify Number of email messages opened Outlook VBA and Custom Forms 7
Witzker Has Outlook 2010 to be opened for Indexing Win7 Using Outlook 1
M contact marked as completed in phone view but not when opened Using Outlook 2
V data files cannot be opened Using Outlook 4
G "Delay Delivery" Email fails to send if opened while in Outbox Using Outlook 4
F Outbox - Multiple Emails need to be manually opened? Using Outlook 5
A Contact address disappears when opened to edit Using Outlook 5
C New emails not appearing until Outlook is closed and re-opened Using Outlook 5
O Multiple simulteniously opened OWA 2010 accounts in one browser work fine ! Using Outlook 3
D Trigger macro to run when selected email is opened Using Outlook 3
M The set of folders cannot be opened. Errors have been detected in the file. Using Outlook 11
O closing outlook prompts to save all opened attachments Using Outlook 2
M Attachments cannot be opened in Outlook, OWA works fine Using Outlook 2
C outlook 2003 always not remove temp copy of opened attachments in temporary fo Using Outlook 4
D Outlook 2010 contacts show old data when opened Using Outlook 1
T Error 'Database msdb cannot be opened' when backing up BCM BCM (Business Contact Manager) 2

Similar threads

Back
Top