?
Solved

Outllook Macro Runtime Error.  Could not find object.

Posted on 2006-11-24
3
Medium Priority
?
274 Views
Last Modified: 2010-04-08
I have created a macro for a pop-up alert to indicate when a new mail message has arrived in a shared public folder inbox.  It works without an issue on one set (Outlook 2003 SP2).  On another, with the same Outlook configuration, I receive the doomed 'runtime error' indicating it can't find an object.  I debug and it

highlights Set flr = ns.Folders(szDir)

The code is thanks to this site and some of my tweaking for path.  Ultimately I want to tweak this to look at three public inboxes and alert our users that a new message has arrived.  Perhaps there is a more efficient way in the code to do this and any help offered would be great.

Obviously I need to fix the runtime error before I go any further.

Here's the code (again thanks to BluDevilFan):
Private WithEvents olkFolder As Outlook.Items
Private WithEvents olkFolderOrders As Outlook.Items

Private Sub Application_Quit()
    Set olkFolder = Nothing
    Set olkFolderOrders = Nothing
End Sub

Private Sub Application_Startup()
    Set olkFolder = OpenMAPIFolder("\Mailbox - Searches Mailbox\Inbox").Items
    Set olkFolderOrders = OpenMAPIFolder("\Mailbox - Orders - Two Rivers Title\Inbox").Items
End Sub

Private Sub olkFolder_ItemAdd(ByVal Item As Object)
    MsgBox "A new item has arrived in the SEARCHES Inbox."
End Sub

Private Sub olkFolderOrders_ItemAdd(ByVal Item As Object)
    MsgBox "A new item has arrived in the ORDERS Inbox."
End Sub

Function OpenMAPIFolder(szPath)
    Dim app, ns, flr, szDir, i
    Set flr = Nothing
    Set app = CreateObject("Outlook.Application")
    If Left(szPath, Len("\")) = "\" Then
        szPath = Mid(szPath, Len("\") + 1)
    Else
        Set flr = app.ActiveExplorer.CurrentFolder
    End If
    While szPath <> ""
        i = InStr(szPath, "\")
        If i Then
            szDir = Left(szPath, i - 1)
            szPath = Mid(szPath, i + Len("\"))
        Else
            szDir = szPath
            szPath = ""
        End If
        If IsNothing(flr) Then
            Set ns = app.GetNamespace("MAPI")
            Set flr = ns.Folders(szDir)
        Else
            Set flr = flr.Folders(szDir)
        End If
    Wend
    Set OpenMAPIFolder = flr
End Function

Function IsNothing(obj)
  If TypeName(obj) = "Nothing" Then
    IsNothing = True
  Else
    IsNothing = False
  End If
End Function

Can someone point me in the right direction? I've patched and updated the PC that gets the runtime error.  I've tried this searching only ONE inbox as well and the same issue.

Thanks!
0
Comment
Question by:pgrazide
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
David Lee earned 2000 total points
ID: 18008485
Greetings, pgrazide.

That error only occurs when the folder path is either incorrect (i.e. there is no such path) or inaccessible.  Have you verified that the shared mailbox is open in the Outlook profile of the user on the computer where this is failing?

Cheers!
0
 

Author Comment

by:pgrazide
ID: 18013385
Sure enough, it was the path!  Weird that it is different from one machine to another.

Truly appreciate your help!
Paul
0
 
LVL 76

Expert Comment

by:David Lee
ID: 18013399
You're welcome, Paul.  Glad I could help.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What does UTC stand for?  “Coordinated Universal Time” – Think of this as the true time on Planet Earth that never changes with the exception of minor leap seconds here and there to account for the changes in the planet's rotation.   What does th…
You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
Many of my clients call in with monstrous Gmail overloading issues with Outlook. A quick tip is to turn off the All Mail and Important folders from synching. Here is a quick video I made to show you how to turn off these and other folders in Gmail s…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question