Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8624681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:35:31+00:00 2026-06-12T07:35:31+00:00

I have written this small program in VS2010 to run on Outlook 2007. It

  • 0

I have written this small program in VS2010 to run on Outlook 2007.

It works for a standard read through of the Inbox, but I cannot get it to correctly point to other Folders, I am getting a “COMException was unhandled by user code” error that says “The operation failed. An object could not be found.” …

I have included a screenshot of my Outlook structure if it helps …

Imports Microsoft.Office.Interop

Public Class ThisAddIn
Private Sub ThisAddIn_Startup() Handles Me.Startup
End Sub
Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
End Sub
Private Sub Application_Startup() Handles Application.Startup

    Dim MyApp As Outlook.Application = New Outlook.Application
    Dim MyNS As Outlook.NameSpace = MyApp.GetNamespace("MAPI")
    Dim MyInbox As Outlook.MAPIFolder = MyNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
    Dim MyEmails As Integer = MyInbox.Items.Count
    Dim MyEMail As Outlook.MailItem
    Dim MyCount As Integer
    Dim MySubFolder As Outlook.MAPIFolder = MyNS.Folders("Kickabout") **<<< Error occurs here**

    For MyCount = MyEmails To 1 Step -1
        MyEMail = MyInbox.Items(MyCount)
        If MyEMail.SenderEmailAddress = "MrX@abc.com" Then
            If MyEMail.Attachments.Count > 0 Then
                MySubFolder = MyNS.Folders("Kickabout\Attachments")
            End If
            MyEMail.Move(MySubFolder)
        End If
    Next
End Sub

End Class

My Outlook Structure

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:35:33+00:00Added an answer on June 12, 2026 at 7:35 am

    OK, I have solved this myself … if anybody is interested in the future, you have to be quite explicit in setting up the path & need a Function to do so, here is the code …

    Imports Microsoft.Office.Interop
    
    Public Class ThisAddIn
    
    Dim strFolderPath As String
    
    Private Sub ThisAddIn_Startup() Handles Me.Startup
    End Sub
    Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
    End Sub
    Private Sub Application_Startup() Handles Application.Startup
    
        Dim MyApp As Outlook.Application = New Outlook.Application
        Dim MyNS As Outlook.NameSpace = MyApp.GetNamespace("MAPI")
        Dim MyInbox As Outlook.MAPIFolder = MyNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
        Dim MyEmails As Integer = MyInbox.Items.Count
        Dim MyEMail As Outlook.MailItem
        Dim MyCount As Integer
        Dim MySubFolder As Outlook.Folder = GetMyFolder("Outlook (Gary)\Kickabout")
        Stop
        For MyCount = MyEmails To 1 Step -1
            MyEMail = MyInbox.Items(MyCount)
            If MyEMail.SenderEmailAddress = "MrX@abc.com" Then
                If MyEMail.Attachments.Count &gt; 0 Then
                    MySubFolder = GetMyFolder("Outlook (Gary)\Kickabout\Attachments")
                End If
                MyEMail.Move(MySubFolder)
            End If
        Next
    End Sub
    
    Function GetMyFolder(FolderPath)
        ' folder path needs to be something like 
        '   "Public Folders\All Public Folders\Company\Sales"
        Dim aFolders
        Dim fldr
        Dim i
        Dim objNS
    
        On Error Resume Next
        strFolderPath = Replace(FolderPath, "/", "\")
        aFolders = Split(FolderPath, "\")
    
        'get the Outlook objects
        ' use intrinsic Application object in form script
        objNS = Application.GetNamespace("MAPI")
    
        'set the root folder
        fldr = objNS.Folders(aFolders(0))
    
        'loop through the array to get the subfolder
        'loop is skipped when there is only one element in the array
        For i = 1 To UBound(aFolders)
            fldr = fldr.Folders(aFolders(i))
            'check for errors
            'If Err() &lt;&gt; 0 Then Exit Function
        Next
        GetMyFolder = fldr
    
        ' dereference objects
        objNS = Nothing
    End Function
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a small program in WindowsXP-python-pygame. It runs fine when I run
I have written this small program for Hive JDBC. Initially it is executing fine
So I am obviously not a very good programmer. I have written this small
I have written this code in JavaScript and works perfectly fine when I include
I have written a small program and compiled it under Solaris/Linux platform to measure
I have written a small program , to understand how futures work in c++0x.
I have written a small program using Borland's C++ builder, and along the way,
I have written a very small C# program, that uses a very small SQL
I have written a small program: void showrecord() { char *a[]={ O_BILLABLE_ACCOUNT,O_CUSTOMER_TYPE_INDICATOR, O_A_PARTY_MSISDN_ID,O_A_PARTY_EQUIPMENT_NUMBER, O_A_PARTY_IMSI,O_A_PARTY_LOCATION_INFO_CELL_ID,
I have written a small C program that embeds Python. I'm setting it up

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.