none
Looping through messages from a outlook add-in RRS feed

  • Question

  • Hi Guys,

    This must be pretty basic for outlook programming,

    I only need to scan through a public folder ( public folder) in outlook 2010.

    I was used to use tha macro's in outlook but when trying to build more advanced stuff i switched to vb.net 2010

    This is a peace of my previous code in a outlook macro. How can I do the same in VB.Net 2010 Outlook Add in ? Thanks

    Public objInbox As Outlook.MAPIFolder
    Public objOutlook As Object
    Public objnSpace As Object

    Dim objMessage As Object
    Dim objSubfolder As Outlook.MAPIFolder
    Dim objSubfolder1 As Outlook.MAPIFolder
    Dim objSubfolder2 As Outlook.MAPIFolder

    Dim recipientName As String

    Function start_up()

    Set objOutlook = CreateObject("Outlook.Application")
    Set objnSpace = objOutlook.GetNamespace("MAPI")

    strUserName = objnSpace.CurrentUser.AddressEntry.GetExchangeUser.PrimarySmtpAddress
    strFolderName = "Public Folders - " & strUserName

    Set objInbox = objnSpace.GetDefaultFolder(olFolderInbox)
    Set objSubfolder0 = objnSpace.Folders(strFolderName)
    Set objSubfolder1 = objSubfolder0.Folders("All Public Folders")
    Set objSubfolder2 = objSubfolder1.Folders("Helpdesk

    For Each objMessage1 In objSubfolder2.Items 'helpdesk
        UserForm1.ListBox6.AddItem (objMessage1.Subject & objMessage1.SentOn)
    Next objMessage1

    Friday, November 16, 2012 8:18 AM

Answers

  • You can use this code almost verbatim.

    Create new vb.net outlook add-in project in Visual Studio and in add-in startup event

    change line

    Set objOutlook = CreateObject("Outlook.Application")

    to

    Set objOutlook = Application

    Friday, November 16, 2012 9:11 AM