• Outlook User
  • Exchange Admin
  • Office 365
  • Outlook Developer
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
    • Common Problems
    • Outlook BCM
    • Utilities & Addins

Outlook VBA: Work with Open Item or Selected Item

Slipstick Systems

› Developer › Outlook VBA: Work with Open Item or Selected Item

Last reviewed on December 4, 2018     64 Comments

To work with the currently selected item (not opened) in the message list, you will need to reference the ActiveExplorer and will use the ActiveExplorer method to get the item in the Explorer window. (This is used for all Outlook items that are selected but not opened: appointments, contacts, tasks, etc.)

Set objItem = objApp.ActiveExplorer.Selection.Item(1)

Selected items uses the Explorer

When you are working with an Outlook item that is open and has focus, it uses the ActiveInspector method. The code you need to work with Inspectors is.

Set objItem = objApp.ActiveInspector.CurrentItem

inspector

To help remember which is which, think of the main Outlook window as Windows Explorer. When you work with items in this window, you'll use Explorer.

 

Use macros with both opened and selected items

When you want to use the macro with both open or selected items, you'll use this function to determine if the item is open or selected. You'll call the function in your code in this manner:

Set objItem = GetCurrentItem()

You'll need to put one copy of this function in a module and can use the function in many macros.

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

These articles are applicable to all versions of Outlook:

More Information

Application.ActiveInspector Method
Application.ActiveExplorer Method

Outlook VBA: Work with Open Item or Selected Item was last modified: December 4th, 2018 by Diane Poremsky
  • Twitter
  • Facebook
  • LinkedIn
  • Reddit
  • Print

Related Posts:

  • This macro copies a meeting request to an appointment. Why would you w
    Copy meeting details to an Outlook appointment
  • Copy Selected Occurrence to an Appointment
  • Created date in table view
    Display the Created Date field of any Outlook item
  • Move Appointments to an Archive Calendar

About Diane Poremsky

A Microsoft Outlook Most Valuable Professional (MVP) since 1999, Diane is the author of several books, including Outlook 2013 Absolute Beginners Book. She also created video training CDs and online training classes for Microsoft Outlook. You can find her helping people online in Outlook Forums as well as in the Microsoft Answers and TechNet forums.

Subscribe
Notify of
64 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Gedhe ND (@guest_219981)
January 15, 2023 7:00 am
#219981

Hi Diane,
can you give an example script for minimize all opened items (appointments) at once?
I want to create custom button in outlook ribbon so when I hit it can minimize all the opened appointment window.
Thank you

0
0
Reply
Philippe Gonin (@guest_218917)
November 29, 2021 5:01 pm
#218917

Bonjour,

Super fonction et mille mercis

Comment modifier cette fonction pour travailler sur un mail en cours d'édition ?

Je vous remercie

Meilleures salutations
Philippe

https://www.developpez.net/forums/d2121684/logiciels/microsoft-office/outlook/suivi-d-message-outlook/#post11788404

0
0
Reply
Philippe Gonin (@guest_218900)
November 21, 2021 5:27 am
#218900

Bonjour,

Comment récupérer le nom du dossier sélectionné dans un mail en cours d'édition ?

Voir image

Je vous remercie
Meilleures salutations
Philippe

2021-11-21_11-27-57.png
0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Philippe Gonin
November 30, 2021 12:40 am
#218918

You need to use getinspector. Depending on what you want to do, you might need to use word object model and inspector.

This has a sample - it formats text, but you can use the same method to insert text or the clipboard contents..
Use Word Macro to Apply Formatting to Email (slipstick.com)

0
0
Reply
Yohann (@guest_217641)
March 2, 2021 6:29 am
#217641

Hello Diane,

is there any way to know, in Inspector case, whether the email has been opened from the hard disk or from Outlook?

Thank you.
Yohann

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Yohann
March 2, 2021 10:23 am
#217646

No, not to my knowledge. You can get the parent - it will always be inbox for messages opened from the file system - but that may not be all that helpful if you are running it on items in the inbox too. .

0
0
Reply
Yohann (@guest_217647)
Reply to  Diane Poremsky
March 2, 2021 10:40 am
#217647

Thank you for the reply.

Totally... there is no differentiation. It appears as it was in the inbox.
I wanted to know that because I propose to user to delete the email from the mailbox once he has exported it in msg format (it is an saving tool); the tool can also be used for an email opened from the file system (for example to make a copy in another folder), but in that latter case, if the user chooses to delete the email source in the mailbox, it generates an error as the email does not come from the mailbox but from the file system.
I get around the problem in resuming the deletion in case of error. It is better than nothing.

Last edited 2 years ago by Yohann
0
0
Reply
Philip GILMAN (@guest_215597)
July 14, 2020 12:59 pm
#215597

Hi Diane,
Thanks for all your help in the past!
Using this GetCurrentItem code has been great for me except for one thing I can't figure out.
If in Explorer, a conversation is selected by the header row of that conversation, this function fails to find the item (or any item) within the conversation. I tried something like:

Set GetCurrentItem = objApp.ActiveExplorer.Selection.GetSelection(olConversationHeaders).GetConversation.Item(1)

but haven't gotten too far. Can you help?
Thx,

Last edited 2 years ago by Philip GILMAN
1
0
Reply
Roland B (@guest_214980)
March 31, 2020 2:58 pm
#214980

I've used this to validate attachment sent outside of my organization. The problem I have with using Set GetCurrentItem = objApp.ActiveExplorer.Selection.Item(1) is if I forward an email with attachments, then delete one or all of those attachments, the script still thinks the attachments are there.

Is there a workaround for that?

0
0
Reply
Jeremy Gura (@guest_214478)
December 16, 2019 11:56 am
#214478

Diane,

I know this is an OLD issue, but I still use the Journal and want to get this to work inside Outlook. I am a neophyte in VBA, but I managed to add Modules for CreateJournalForcontact and I also have a Module for GetCurrentItem as per your instructions, but I continue to get the "Sorry you need to select a contact" error. Can you help me figure out what I may have done wrong???

0
0
Reply
Kim A (@guest_213792)
August 19, 2019 5:42 pm
#213792

For me to get this to work I had to remove objApp. I.e. I changed this:
Set objItem = objApp.ActiveExplorer.Selection.Item(1)

to this:
Set objItem = ActiveExplorer.Selection.Item(1)

Otherwise I got some error, I believe run-time error 424 Object required

0
0
Reply

Visit Slipstick Forums.
What's New at Slipstick.com

Latest EMO: Vol. 28 Issue 11

Support Services

Do you need help setting up Outlook, moving your email to a new computer, migrating or configuring Office 365, or just need some one-on-one assistance?

Subscribe to Exchange Messaging Outlook






Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • WeekMonthAll
  • Adjusting Outlook's Zoom Setting in Email
  • How to Remove the Primary Account from Outlook
  • Cannot add Recipients in To, CC, BCC fields on MacOS
  • Move an Outlook Personal Folders .pst File
  • Save Sent Items in Shared Mailbox Sent Items folder
  • Create rules that apply to an entire domain
  • Outlook's Left Navigation Bar
  • Remove a password from an Outlook *.pst File
  • Use PowerShell to get a list of Distribution Group members
  • View Shared Calendar Category Colors
  • Cannot add Recipients in To, CC, BCC fields on MacOS
  • Change Appointment Reminder Sounds
  • Messages appear duplicated in message list
  • Reset the New Outlook Profile
  • Delete Old Calendar Events using VBA
  • Use PowerShell or VBA to get Outlook folder creation date
  • Outlook's Left Navigation Bar
  • Contact's Display Bug
  • Use PowerShell to get a list of Distribution Group members
  • Edit Outlook’s Attach File list
Ajax spinner

Newest Code Samples

Delete Old Calendar Events using VBA

Use PowerShell or VBA to get Outlook folder creation date

Rename Outlook Attachments

Format Images in Outlook Email

Set Outlook Online or Offline using VBScript or PowerShell

List snoozed reminders and snooze-times

Search your Contacts using PowerShell

Filter mail when you are not the only recipient

Add Contact Information to a Task

Process Mail that was Auto Forwarded by a Rule

Recent Bugs List

Microsoft keeps a running list of issues affecting recently released updates at Fixes or workarounds for recent issues in Outlook for Windows.

Outlook for Mac Recent issues: Fixes or workarounds for recent issues in Outlook for Mac

Office Update History

Update history for supported Office versions is at Update history for Office

Outlook Suggestions and Feedback

Outlook Feedback covers Outlook as an email client, including Outlook Android, iOS, Mac, and Windows clients, as well as the browser extension (PWA) and Outlook on the web.

Use Outlook.com Feedback for suggestions or feedback about Outlook.com accounts.

Other Microsoft 365 applications and services




Windows 10 Issues

  • iCloud, Outlook 2016, and Windows 10
  • Outlook Links Won’t Open In Windows 10
  • Outlook can’t send mail in Windows 10: error Ox800CCC13
  • Missing Outlook data files after upgrading Windows?

Outlook Top Issues

  • The Windows Store Outlook App
  • The Signature or Stationery and Fonts button doesn’t work
  • Outlook’s New Account Setup Wizard
  • Outlook 2016: No BCM
  • Exchange Account Set-up Missing in Outlook 2016

VBA Basics

How to use the VBA Editor

Work with open item or selected item

Working with All Items in a Folder or Selected Items

VBA and non-default Outlook Folders

Backup and save your Outlook VBA macros

Get text using Left, Right, Mid, Len, InStr

Using Arrays in Outlook macros

Use RegEx to extract message text

Paste clipboard contents

Windows Folder Picker

Custom Forms

Designing Microsoft Outlook Forms

Set a custom form as default

Developer Resources

Developer Resources

Developer Tools

Outlook-tips.net Samples

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

MSDN Outlook Dev Forum

Repair PST

Convert an OST to PST

Repair damaged PST file

Repair large PST File

Remove password from PST

Merge Two Data Files

Sync & Share Outlook Data

  • Share Calendar & Contacts
  • Synchronize two computers
  • Sync Calendar and Contacts Using Outlook.com
  • Sync Outlook & Android Devices
  • Sync Google Calendar with Outlook
  • Access Folders in Other Users Mailboxes

Contact Tools

Data Entry and Updating

Duplicate Checkers

Phone Number Updates

Contact Management Tools

Diane Poremsky [Outlook MVP]

Make a donation

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Productivity

Productivity Tools

Automatic Message Processing Tools

Special Function Automatic Processing Tools

Housekeeping and Message Management

Task Tools

Project and Business Management Tools

Choosing the Folder to Save a Sent Message In

Run Rules on messages after reading

Help & Suggestions

Outlook Suggestion Box (UserVoice)

Slipstick Support Services

Home | Outlook User | Exchange Administrator | Office 365 | Outlook.com | Outlook Developer
Outlook for Mac | Common Problems | Utilities & Addins | Tutorials
Outlook & iCloud Issues | Outlook Apps
EMO Archives | About Slipstick | Advertise | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2023 Slipstick Systems. All rights reserved.
Slipstick Systems is not affiliated with Microsoft Corporation.

wpDiscuz

Sign up for Exchange Messaging Outlook

Our weekly Outlook & Exchange newsletter (bi-weekly during the summer)






Please note: If you subscribed to Exchange Messaging Outlook before August 2019, please re-subscribe.

Never see this message again.

You are going to send email to

Move Comment