Outlook account subfolders - Outlook VB coding

Status
Not open for further replies.

Zditsky

Member
Outlook version
Outlook 2013 64 bit
Email Account
POP3
Prior to Outlook 2013, I was able to access emails that were diverted to a sub folder of the InBox. Code was




Set myOlApp = CreateObject("Outlook.Application")


Set myNameSpace = myOlApp.GetNamespace("MAPI")


Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox) ' Inbox folder


Set mySubFolder(2) = myFolder.Folders("PHY2049") ' Inbox subfolder containing files


Set mySubFolder(1) = myFolder.Folders("PHY2048") ' Inbox subfolder containing files


Set mySelection = myOlApp.ActiveExplorer.Selection




Now I get as object error at Set mySubFolder(2)=..... I have 3 email accounts being controlled by Outlook. So I tried the following code assuming I correctly set the default account with the statement:


Set oAccount = myOlApp.Session.Accounts.Item(2)


Dim oAccount As Outlook.Account


Set myOlApp = CreateObject("Outlook.Application")


Set myNameSpace = myOlApp.GetNamespace("MAPI")


Set oAccount = myOlApp.Session.Accounts.Item(2) '==


Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox) ' Inbox folder


Set mySubFolder(2) = myFolder.Folders("PHY2049") '




Inbox subfolder containing files Same error. How do I code to define the subfolders of the oAccount?? Thanks Z
 
The first code should still work if the account is the default account. If its one of the other 2 accounts, you need to use the getfolderpath function at http://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/

- - - Updated - - -

The first code should still work if the account is the default account. If its one of the other 2 accounts, you need to use the getfolderpath function at http://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/
 
Prior to Outlook 2013, I was able to access emails that were diverted to a sub folder of the InBox. Code was

Set myOlApp = CreateObject("Outlook.Application")

Set myNameSpace = myOlApp.GetNamespace("MAPI")

Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox) ' Inbox folder

Set mySubFolder(2) = myFolder.Folders("PHY2049") ' Inbox subfolder containing files

Set mySubFolder(1) = myFolder.Folders("PHY2048") ' Inbox subfolder containing files

Set mySelection = myOlApp.ActiveExplorer.Selection

Now I get as object error at Set mySubFolder(2)=..... I have 3 email accounts being controlled by Outlook. So I tried the following code assuming I correctly set the default account with the statement:

Set oAccount = myOlApp.Session.Accounts.Item(2)

Dim oAccount As Outlook.Account

Set myOlApp = CreateObject("Outlook.Application")

Set myNameSpace = myOlApp.GetNamespace("MAPI")

Set oAccount = myOlApp.Session.Accounts.Item(2) '==

Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox) ' Inbox folder

Set mySubFolder(2) = myFolder.Folders("PHY2049") '

Inbox subfolder containing files Same error. How do I code to define the subfolders of the oAccount?? Thanks Z

=============

I applied the suggested addition so that the code looks as follows
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")


Dim items

Set items = GetFolderPath("\\myEmail@gmail.com\inbox").items

'==
Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox) ' Inbox folder

Set mySubFolder(2) = myFolder.Folders("PHY2049") ' Inbox subfolder containing files
Set mySubFolder(1) = myFolder.Folders("PHY2048") ' Inbox subfolder containing files
Set mySelection = myOlApp.ActiveExplorer.Selection


I continue to get an error message: The attempted operation failed. An objest could not be found

Suggestions please

Z
 
The first code should still work if the account is the default account. If its one of the other 2 accounts, you need to use the getfolderpath function at http://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/

- - - Updated - - -

The first code should still work if the account is the default account. If its one of the other 2 accounts, you need to use the getfolderpath function at http://www.slipstick.com/developer/working-vba-nondefault-outlook-folders/

Reset the code as follows:
Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")


Dim items

Set items = GetFolderPath("\\myEmail@gmail.com\inbox").items

'==
Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox) ' Inbox folder

Set mySubFolder(2) = myFolder.Folders("PHY2049") ' Inbox subfolder containing files
Set mySubFolder(1) = myFolder.Folders("PHY2048") ' Inbox subfolder containing files
Set mySelection = myOlApp.ActiveExplorer.Selection


Getting the error message @ Set mySubFolder(2) = myFolder.Folders("PHY2049"): .....an object could not be found

I'm not a programmer, so any code example would be most helpfull

Z
 
So your folder path is

Root of Data file - named either personal folders or your email address

-- Inbox

---- PHY2048

---- PHY2049

If so, then myFolder.GetDefaultFolder(olFolderInbox).Folders("PHY2049") path is work, and your code is the shortened version, so it should work too. That leaves the error on mySubfolder(2) being the object it can't find. I'll take a look at it later tonight.
 
Set mySubFolder(1) = GetFolderPath("\\prof.smith.pbsc@gmail.com\inbox\PHY2048") '.items


Set mySubFolder(2) = GetFolderPath("\\prof.smith.pbsc@gmail.com\inbox\PHY2049") '.items
 
Gave up trying to be elegant and went with the following code format - it worked

Set mySubFolder(1) = GetFolderPath("\\email account\inbox\subfolder1name")

Set mySubFolder(2) = GetFolderPath("\\email account\inbox\subfolder2name")

Z
 
Gave up trying to be elegant and went with the following code format - it worked

Set mySubFolder(1) = GetFolderPath("\\email account\inbox\subfolder1name")

Set mySubFolder(2) = GetFolderPath("\\email account\inbox\subfolder2name")

Z

Are the folders in the default pst file? If not, you definitely need to use getfolderpath.
 
How do I tell?

They're listed under the default account as it's displayed in Outlook 2013.

Z
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
L I Cannot Sign Into My Outlook Account? Outlook VBA and Custom Forms 0
e_a_g_l_e_p_i Question about installing my Gmail account on my iPhone but still getting messages downloaded to my desktop Outlook. Using Outlook 3
J GoDaddy migrated to Office365 - Outlook Wont Add Account Exchange Server Administration 21
HarvMan Outlook.com Account Using Outlook 3
D Office 365 Outlook desktop app prompts for all account passwords on startup Using Outlook 11
L Recommendations for Utility to Backup Outlook 365 Account Settings Using Outlook 2
T How to configure Outlook for two users on a single Windows account Using Outlook 3
Commodore Any way to create "from-only" account on Outlook 2021? Using Outlook 1
Z Remove GMAIL IMAP account from Outlook 2016 Using Outlook 2
C Outlook 2007 Removing then adding account restores junk email processing Using Outlook 0
M How to setup outlook after importing old account information - Entering email account info creates with "(1)" after the account! Using Outlook 1
F Excel VBA to move mails for outlook 365 on secondary mail account Outlook VBA and Custom Forms 1
e_a_g_l_e_p_i Outlook 2010 Help setting up Gmail account in Outlook 2010 Using Outlook 3
C WARNING - DO NOT USE AN OUTLOOK.COM ADDRESS FOR GOOGLE ACCOUNT RECOVERY EMAIL Using Outlook 10
G Outlook 365 with iCloud account not syncing calendars Using Outlook 2
D Outlook 2016 how to use gmail account as source account for outlook 365 Using Outlook 9
M Outlook on 3 Computers Shows Different Total Items on Same Account Using Outlook 3
C Outlook with Office365 - search across account, by date rate, in multiple folders - how? Using Outlook 2
M Microsoft 365 Outlook keeps requesting password on Local Account Using Outlook 1
R How to get the Items object of the default mailbox of a specific account in a multiple account Outlook? Outlook VBA and Custom Forms 0
O Email not leaving Outbox when using Excel VBA to sync Outlook account Outlook VBA and Custom Forms 4
D Outlook 2016 Migrate 'On My Computer' (local storage) Calendar from Mac Outlook to Exchange Account Using Outlook 5
Marc2019 Need help please! Cannot Setup my outlook email account on my Mac Outlook 2011 Using Outlook.com accounts in Outlook 2
M Gmail is not downloading in my outlook account Using Outlook 0
D Outlook 2010 account setup fails in particular domain Using Outlook 3
W Account icons Outlook for Android Using Outlook 1
Marc2019 Setting up an Outlook Account on Mac Os 10.6.8 Outlook 2011 Using Outlook 1
Marc2019 Cannot setup Outlook Account on Mac Os 10.6.8 Using Outlook 3
D Adding Enterprise Exchange Email Account to Outlook Prevents Sending via Outlook.com Account Using Outlook.com accounts in Outlook 10
F Send As a Gmail account via outlook Web Using Outlook 3
T Outlook changes default account Using Outlook 1
E Unable to open Outlook 2010 after adding new email account Using Outlook 4
T Migrating Profile/Account Settings To New PC for Outlook 2016 Using Outlook 2
L Need to import multiple Outlook files to Office 365 Account Using Outlook 4
T Copying Outlook Account Setup For Desktop App Using Outlook 5
N Error 0x80090326 when trying to setup IMAP account on Outlook.com Using Outlook.com accounts in Outlook 1
P Outlook.com account overrules default account Using Outlook.com accounts in Outlook 8
R Email account works on thunderbird not Outlook Using Outlook 6
Bob Franklin Emails Not Received in my Outlook account Using Outlook 1
T Changing default Mail Account in Outlook 2016 - POP3 Using Outlook 1
R Add Exchange Account to existing POP3 Outlook 2007 Profile Using Outlook 0
T Probem with junk mail folder in new account in Outlook Using Outlook 0
J Change POP account to Forwarder - What happens in Outlook? Using Outlook 2
mrje1 Outlook 2016 Manual Email Account Setup, what is the Office 365 option etc., and Crashes Using Outlook 0
V Hotmail account on Outlook 2010 Using Outlook 2
M Unable to Configure Gmail Account in Outlook 2007 Using Outlook 1
Diane Poremsky Setting up an Outlook.com IMAP account Using Outlook 0
Diane Poremsky Manually create a POP3 account in Outlook 2007 Using Outlook 0
A Outlook 2016 - adding outlook.com account creates a new/strange address Using Outlook.com accounts in Outlook 18
C Outlook VBA to set current account Outlook VBA and Custom Forms 1

Similar threads

Back
Top