melodramatic
Board Regular
- Joined
- Apr 28, 2003
- Messages
- 187
- Office Version
- 365
- Platform
- 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.
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!
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!