• Outlook User
  • New Outlook app
  • Outlook.com
  • Outlook Mac
  • Outlook & iCloud
  • Developer
  • Microsoft 365 Admin
    • Common Problems
    • Microsoft 365
    • Outlook BCM
    • Utilities & Addins

Process items in a shared mailbox

Slipstick Systems

› Developer › Code Samples › Process items in a shared mailbox

Last reviewed on February 11, 2016     19 Comments

Client-side rules won't run if the mailbox is not open in Outlook and you can't run rules on a shared mailbox in your profile. However, if the shared mailbox is in your profile you can use an ItemAdd macro to watch the folder for new items and process them as they arrive.

This sample watches a shared mailbox for new items, adds a category to the item then forwards it to another address.

How to use VBA macros

To get the correct mailbox name to use, right-click on the shared Inbox and choose Properties. The mailbox name is in the Location field.

Use the name only, not the \\.
Get the mailbox name from properties

 Private WithEvents olInboxItems As Items

Private Sub Application_Startup() 
  Dim objNS As NameSpace
  Set objNS = Application.Session

' Get function fromhttp://slipstick.me/qf
  Set olInboxItems = GetFolderPath("Mailbox name in folder list\Inbox").Items
  Set objNS = Nothing
End Sub

Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
  On Error Resume Next

    Item.Categories = "My Category"
    Item.Save
 
  Set myForward = Item.Forward
  'this puts the name in the To field
  myForward.Recipients.Add "me@domain.com"
  myForward.Display ' use .Send to send it automatically

End Sub

Don't forget to check your macro security settings; it needs to be set to Low for testing.

To test the macro without restarting Outlook, click in the Application_Startup macro and press Run.

How to use macros

First: You will need macro security set to low during testing.

To check your macro security in Outlook 2010 or 2013, go to File, Options, Trust Center and open Trust Center Settings, and change the Macro Settings. In Outlook 2007 and older, it’s at Tools, Macro Security.

After you test the macro and see that it works, you can either leave macro security set to low or sign the macro.

Open the VBA Editor by pressing Alt+F11 on your keyboard.

To put the code in a module:

  1. Right click on Project1 and choose Insert > Module
  2. Copy and paste the macro into the new module.

More information as well as screenshots are at How to use the VBA Editor

Process items in a shared mailbox was last modified: February 11th, 2016 by Diane Poremsky

Related Posts:

  • Use a VBA macro to monitor a folder in a secondary mailbox for new mes
    Monitor secondary mailbox folder for new messages
  • Process Mail that was Auto Forwarded by a Rule
  • Mark Sent Items as Read After Copying with a Rule
  • How to Process Mail After Business Hours

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
19 Comments
newest
oldest most voted
Inline Feedbacks
View all comments

Shreyas (@guest_215335)
June 4, 2020 7:12 am
#215335

I have put the above codes by changing the shared mailbox name and forward too section however it gives an error stating "Only Valid in object Module" for  "Private WithEvents olInboxItems As Items" . Please help.
I also need a macro where in all attachments can be downloaded from shared mailbox.

0
0
Reply
Brian (@guest_210564)
March 9, 2018 12:22 pm
#210564

Hi Diane, My question is a bit more complex. I have a macro that uploads attachments from a shared mailbox into a master file on the network. Because there is no reliable method of determining which emails have the necessary attachments, the user sets a custom Category on the required emails. The macro loops through the mailbox, uploads attachments from the categorized emails, then switches the custom Category to "Upload Complete". All of this works perfectly... Unless... If another user happens to have one of the categorized emails open, the macro adds the "Upload Complete" category to the email, but cannot remove the "Ready For Upload". This causes the "Ready For Upload" Category count to hang at 1 and the macro loops forever. Note: I cannot simply count the "Ready For Upload" emails because the Email.Save process which is switching the category interrupts For Each loops so I have to use a Do Until loop. So, is there a way to close or deactivate an email from all users, or identify if another user has an email open, or lock an email by some means so others can't open it during this process? Any assistance you can provide is greatly… Read more »

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Brian
March 16, 2018 11:51 pm
#210662

Well.. you can't close it remoting using vba.

I am assuming redemption won't close it either, but have not looked at it... but if it can be done, I'd expect redemption to do it. http://www.dimastr.com/redemption/rdo_introduction.htm

0
0
Reply
JMay (@guest_209510)
November 29, 2017 4:44 am
#209510

Hi , I need to build a macro to track the mails moved from one mail box to other in a shared mail box in excel ,Can anyone please help me on this ?

0
0
Reply
Rajneesh (@guest_206636)
May 19, 2017 11:10 am
#206636

Hi Diane,
Any idea how to automate the process to send the E-mails from Office 365.

Regards
Rajneesh

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Rajneesh
May 19, 2017 10:58 pm
#206648

If its a shared mailbox, you need to have send as permission and use .sentonbehalfof - https://www.slipstick.com/developer/code-samples/send-email-address-vba/

0
0
Reply
Rajneesh (@guest_205503)
March 27, 2017 11:11 am
#205503

Hi, I am stuck in one of the urgent project delivery. Requirement is: when new mail arrives, mail detail(Subject,received time) should be export into excefl but main issue is that user have 6 different shared inbox and these inbox we have 2 or 3 folder in each.
Outlook event for new mail is not working for these inbox , it is notifying new mails only for main inbox.
Please help!!!

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Rajneesh
March 29, 2017 3:35 pm
#205533

you'll need to add each folder you need to watch to the automatic startup macro and create an items add macro for each one, giving each a different name. It's going to get real messy, real fast watching 12 - 18 folders - start with one folder, test, then add more. Make sure you are using unique object names for each folder too.

if the macro to save to excel is identical for each, the itemadd macros can call the same macro, which will reduce a lot of the mess.

You can set the parent folder once (so you only need 6 of these) - and share that with the subfolders:
Set Aliasfolder = Session.GetDefaultFolder(olFolderInbox)
set aliaisitems = aliasfolder.items
set aliassubfolder1items = aliasfolder.Folders("Sub1").Items
set aliassubfolder2items = aliasfolder.Folders("Sub2").Items

Private Sub aliaisitems_ItemAdd(ByVal Item As Object)
'do whatever
call savetoexel
end sub

Private Sub aliassubfolder1items_ItemAdd(ByVal Item As Object)
'do whatever
call savetoexel
end sub

Private Sub aliassubfolder2items_ItemAdd(ByVal Item As Object)
'do whatever
call savetoexel
end sub
etc

1
0
Reply
Rajneesh (@guest_205839)
Reply to  Diane Poremsky
April 11, 2017 12:39 pm
#205839

Hi Diana, Thanks for the response. I used "GetFolderPath" function for each folder that i got from your above code and it's working good and very helpful. My project is in progress now and it is in testing phase. Can you please suggest how can we assign the outlook code to button for whole team rather than import and export the module and assign the button one by one for each team memeber system.

Thanks for your support:):)

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Rajneesh
April 14, 2017 8:27 pm
#205916

i swear i answered this the other day... guess i forgot to hit send. :) the only way to share code is either by import/export or copy/paste it or compiling it into an addin.

0
0
Reply
Marara (@guest_205239)
March 14, 2017 3:39 pm
#205239

Hi, Im pretty new to VBA and Outlook, Here is the issue I'm having. We have public folder that each team member has access to and we have our own personal one. I used the following code to move email from Inbox to subfolder in public folder. It works perfectly on my machine but for everyone else the email stays in the Inbox. I cant see the email even if I restart outlook. It is also in the subfolder
Set ns = Application.GetNamespace("MAPI")
Set objOwner = ns.CreateRecipient("general@u.ca")
objOwner.Resolve
If objOwner.Resolved Then
Set newCalFolder = ns.GetSharedDefaultFolder(objOwner, olFolderInbox)
Set objDestFolder = newCalFolder.Folders("Myfolder")
End If
Set objItem = GetCurrentItem()
With objItem
.FlagStatus = olFlagComplete
.Move objDestFolder
End With
Any help is greatly appreciated

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Marara
March 14, 2017 4:34 pm
#205244

Did the other users add the shared mailbox in their profile the same way you did? Do they get any error messages?

0
0
Reply
Drew G (@guest_204420)
February 7, 2017 4:57 pm
#204420

Hi Diane,

I am using a shared inbox and I am trying to create a rule that will move mail to a specific folder based on certain words that appear in the body. In outlook when I try and create the rule it does not let me select the folder of the shared inbox. I can do it using OWA but the issue there is I want to be able to save the rules in case they are deleted in error. Any ideas?

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Drew G
March 14, 2017 4:15 pm
#205241

if its a server side rule, you can create a profile for the shared account to create the rules, then go back to your own profile, otherwise you need to use a macro that watches the shared inbox, which is on this page. .

0
0
Reply
Rajneesh (@guest_205502)
Reply to  Diane Poremsky
March 27, 2017 11:01 am
#205502

hi Diane,

Cud u plz share the code for watch the new mail arrival on shared inbox.

0
0
Reply
Diane Poremsky(@diane-poremsky)
Author
Reply to  Rajneesh
March 29, 2017 3:25 pm
#205532

You'll use the method at https://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/#shared to identify the folder to watch.

it replaces this line -
Set olInboxItems = GetFolderPath("Mailbox name in folder list\Inbox").Items
just make sure you are using the correct object references!

0
0
Reply
Louis (@guest_201331)
September 3, 2016 9:50 am
#201331

I am getting the sub or function error under
GetFolderPath you please help?

0
0
Reply

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

Latest EMO: Vol. 30 Issue 15

Subscribe to Exchange Messaging Outlook






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?

Our Sponsors

CompanionLink
ReliefJet
  • Popular
  • Latest
  • Week Month All
  • Use Classic Outlook, not New Outlook
  • How to Remove the Primary Account from Outlook
  • Disable "Always ask before opening" Dialog
  • Adjusting Outlook's Zoom Setting in Email
  • This operation has been cancelled due to restrictions
  • Remove a password from an Outlook *.pst File
  • Reset the New Outlook Profile
  • Maximum number of Exchange accounts in an Outlook profile
  • Save Attachments to the Hard Drive
  • How to Hide or Delete Outlook's Default Folders
  • Google Workspace and Outlook with POP Mail
  • Import EML Files into New Outlook
  • Opening PST files in New Outlook
  • New Outlook: Show To, CC, BCC in Replies
  • Insert Word Document into Email using VBA
  • Delete Empty Folders using PowerShell
  • Warn Before Deleting a Contact
  • Classic Outlook is NOT Going Away in 2026
  • Use PowerShell to Delete Attachments
  • Remove RE:, FWD:, and Other Prefixes from Subject Line
Ajax spinner

Recent Bugs List

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

For new Outlook for Windows: Fixes or workarounds for recent issues in new Outlook for Windows .

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

Outlook.com Recent issues: Fixes or workarounds for recent issues on Outlook.com

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.

Outlook (new) Feedback. Use this for feedback and suggestions for Outlook (new).

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

Other Microsoft 365 applications and services




New Outlook Articles

Google Workspace and Outlook with POP Mail

Import EML Files into New Outlook

Opening PST files in New Outlook

New Outlook: Show To, CC, BCC in Replies

Insert Word Document into Email using VBA

Delete Empty Folders using PowerShell

Warn Before Deleting a Contact

Classic Outlook is NOT Going Away in 2026

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Newest Code Samples

Insert Word Document into Email using VBA

Warn Before Deleting a Contact

Use PowerShell to Delete Attachments

Remove RE:, FWD:, and Other Prefixes from Subject Line

Change the Mailing Address Using PowerShell

Categorize @Mentioned Messages

Send an Email When You Open Outlook

Delete Old Calendar Events using VBA

Use PowerShell or VBA to get Outlook folder creation date

Rename Outlook Attachments

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

VBOffice.net samples

SlovakTech.com

Outlook MVP David Lee

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

Diane Poremsky [Outlook MVP]

Make a donation

Mail Tools

Sending and Retrieval Tools

Mass Mail Tools

Compose Tools

Duplicate Remover Tools

Mail Tools for Outlook

Online Services

Calendar Tools

Schedule Management

Calendar Printing Tools

Calendar Reminder Tools

Calendar Dates & Data

Time and Billing Tools

Meeting Productivity Tools

Duplicate Remover Tools

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

Submit Outlook Feature Requests

Slipstick Support Services

Buy Microsoft 365 Office Software and Services

Visit Slipstick Forums.

What's New at Slipstick.com

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 | Slipstick Forums
Submit New or Updated Outlook and Exchange Server Utilities

Send comments using our Feedback page
Copyright © 2025 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