Trying to work with OutlookFolder subfolders

melodramatic

Board Regular
Joined
Apr 28, 2003
Messages
187
Office Version
  1. 365
Platform
  1. Windows
I've made a macro (copying bits and pieces from here and there) that I want to use to be able to click it daily to see if any new projects have been sent my way, and then pull the info from those projects to post into my project data list.

First of all, I'm in Office 365.

Anytime the system sends me the new project data, it automatically goes to a subfolder of the Inbox called "SPACE163". I have tried to get the system to pick up my subfolder when searching mail, and it just flat won't do it. When I try to run the following code, I get "Run-time error '-2147221233 (8004010f)' The attempted operation failed. An object could not be found" at the line where I'm trying to set the Subfolder.

The macro works if I go to the Inbox.

VBA Code:
Sub NewProjects()

Dim olApp As Outlook.Application
Dim olNamespace As Namespace
Dim olFolder As MAPIFolder
Dim olSub As MAPIFolder
Dim olMail As Variant
Dim i As Integer
Dim nextRow As Long

Set olApp = New Outlook.Application
Set olNamespace = olApp.GetNamespace("MAPI")
Set olFolder = olNamespace.GetDefaultFolder(olFolderInbox)
Set olSub = olFolder.Folders("SPACE163") ' THIS IS WHERE I GET THE ERROR, in trying to assign the sub-folder
i = 1

For Each olMail In olSub.Items
NextRow = Range("F1")
Range("A" & nextrow).Value = olMail.ReceivedTime
Range("B" & nextrow).Value = olMail.Body

i = i + 1

Next olMail
Set olFolder = Nothing
Set olSub = Nothing
Set olNamespace = Nothing
Set olApp = Nothing

MsgBox nextrow & " New Projects have been received."
End Sub

I've been able to get around the problem by temporarily turning off my Outlook Rule that sends the emails to the subfolder, leaving them in the default Inbox and grabbing only items sent by Space, but it would sure help to figure out how to be able to go back to my subfolder.

Can anyone point out what I might be doing wrong? Appreciate it much!
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Hoping that this will bump the thread. I do have all of the Microsoft Outlook options selected as References in the VBA Tools.

Capture.JPG
 
Upvote 0

Forum statistics

Threads
1,224,824
Messages
6,181,187
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top