Microsoft Office Forums Reading msgs from specific inbox

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-26-2018, 05:08 AM
MarkAtTheBeach MarkAtTheBeach is offline Reading msgs from specific inbox Windows 10 Reading msgs from specific inbox Office 2016
Novice
Reading msgs from specific inbox
 
Join Date: Oct 2018
Posts: 4
MarkAtTheBeach is on a distinguished road
Default Reading msgs from specific inbox

Am trying to read email from Outlook. In VBA, I create an outlook session, then read the inbox with:




oSession.logon()
oInbox = oSession.GetDefaultFolder(6)


But if the user has more than one account, cannot figure how I can get the inbox for a specific account just using the email address or the account name.


Any help greatly appreciated,
Mark
Reply With Quote
  #2  
Old 10-26-2018, 09:29 PM
gmayor's Avatar
gmayor gmayor is offline Reading msgs from specific inbox Windows 10 Reading msgs from specific inbox Office 2016
Expert
 
Join Date: Aug 2014
Posts: 2,900
gmayor is just really nicegmayor is just really nicegmayor is just really nicegmayor is just really nice
Default

You would need to identify the Store that contains the inbox e.g.


Code:
Dim oFolder As Folder
    Set oFolder = Session.Stores.Item("Name of Store").GetDefaultFolder(olFolderInbox)
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 10-27-2018, 12:48 PM
MarkAtTheBeach MarkAtTheBeach is offline Reading msgs from specific inbox Windows 10 Reading msgs from specific inbox Office 2016
Novice
Reading msgs from specific inbox
 
Join Date: Oct 2018
Posts: 4
MarkAtTheBeach is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
You would need to identify the Store that contains the inbox e.g.


Code:
Dim oFolder As Folder
    Set oFolder = Session.Stores.Item("Name of Store").GetDefaultFolder(olFolderInbox)

Thanks,


Have struggled with this, but this was very helpful.



So "Name of Store" is the specific email address I wish to monitor. From that I can get the incoming msgs (item) in the inbox.



A related question - Users will sometimes move a new msg from inbox to specially named folders like PastDueBill, Personal, etc. If they do so before I am able to pick up the new msgs in inbox, could you help me on the syntax for checking each of these other custom mailboxes they created? Also, how would I get the names of these other mailboxes they are using mostly for storage?


Again, many thanks for clearing up this Store concept for me.


Mark
Reply With Quote
  #4  
Old 10-27-2018, 11:54 PM
gmayor's Avatar
gmayor gmayor is offline Reading msgs from specific inbox Windows 10 Reading msgs from specific inbox Office 2016
Expert
 
Join Date: Aug 2014
Posts: 2,900
gmayor is just really nicegmayor is just really nicegmayor is just really nicegmayor is just really nice
Default

You can loop through the stores and get their names and by adding them to a collection you can loop through the names e.g. as follows. However due to the many ways that Outlook can be configured, you may get duplicates. If the following shows duplicates with the same message counts then you can remove the duplicates by using. As you may not know what you are dealing with it may be better to simply leave the duplicates and process the folder twice.

Code:
oColl.Add oStore, oStore
'in place of
oColl.Add oStore
to add to the collection
Code:
Sub Macro1()
 Dim oStore As Store
Dim oFolder As Folder
Dim oColl As Collection
Dim i As Integer
    Set oColl = New Collection
    On Error Resume Next
    For Each oStore In Session.Stores
Debug.Print oStore
        oColl.Add oStore
    Next oStore
    On Error GoTo 0
    For i = 1 To oColl.Count
        Set oFolder = Session.Stores.Item(CStr(oColl(i))).GetDefaultFolder(olFolderInbox)
        'do something with ofolder
Debug.Print oFolder.Items.Count
    Next i
lbl_Exit:
    Set oFolder = Nothing
    Set oStore = Nothing
    Set oColl = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
Reply

Tags
getdefaultfolder, reading mail

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Saved .msgs copies locked asd12 Outlook 1 07-27-2018 06:32 AM
Inbox rule to move everything from Junk to Inbox automatically? sand3 Outlook 0 02-07-2017 12:38 PM
How to stop OL from showing connection lost msgs.? mmo Outlook 0 01-14-2016 04:33 AM
Reading pane on TOP? hehunt Outlook 0 04-10-2014 06:34 AM
Reading msgs from specific inbox How to save a PPT file in 'Reading View' to be opened always in 'Reading View' ItzVickey PowerPoint 2 08-08-2012 09:23 AM


All times are GMT -7. The time now is 03:46 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2019 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft