Macro code does not work twice

Self build / N/A
January 31, 2009 at 17:42:37
Specs: WinXP, 1.5Ghz, 256MB
I created a macro in Outlook VBA. The macro worked fine. Now, I am creating a new macro with same exact code but for some reason it's not working. Here is some lines of code:

Dim olApp as Outlook.Application
dim mb as MapiFolder
dim ns as namespace

set olApp = CreateObject ("Outlook.Application")
set ns = olApp.Mapinamespace
set mb = ns.folders.item(mailbox).folders.item(folder).folders.item(subfolder)

The last line generates the error where in the other macro the same line works OK. I am trying to get to a subfolder to get a count of the items in it.



See More: Macro code does not work twice

Report •


#1
February 2, 2009 at 08:09:39
Let me guess, subscript out of range? You declare neither mailbox, folder, nor subfolder. You would have noticed that if you had used Option Explicit.

Report •

#2
February 3, 2009 at 19:04:20
Razor2.3,
I thought the MapiFolder object covered all those. The error is: Object could not be found.

Report •

#3
February 4, 2009 at 01:10:11
CyberDude: I thought the MapiFolder object covered all those.

VBA's Immediate Window:

debug.Print vartype(mailbox), _
            vartype(folder), _
            vartype(subfolder)
 0             0             0 

Apperently not.

CyberDude: The error is: Object could not be found.
Then something in that chain returns nothing. I'm not sure if it's mailbox(0), the folders(0), or the other folders(0), but something in that chain returns Nothing.

I'd check the script you copy/pasted from. I bet you somewhere, they define those variables.


Report •

Related Solutions

#4
February 8, 2009 at 18:50:35
Razor 2.3:
I've resolved the issue. I had to use the Recipient object to get to a shared mail box folder and then from there get to the subfolder. Instead of Folders.Folder("whatever"), I had to use Folders.Items(4). My path down the object hierarchy apparently is a little different since Folders.Folder did not work for me. Thanks for your input.

Report •


Ask Question