Outlook.PickerDialog Method in MS Outlook 2010 to Access a SharePoint Server in VB.NET

In this article I am going to explain about how to get a list of objects such as users, distribution lists, and so forth in Microsoft Outlook 2010.
  • 3558

Introduction

In this article I am going to explain about how to get a list of objects such as users, distribution lists, and so forth in Microsoft Outlook 2010. For this we use PickerDialog object and Outlook.PickerDialog Method in Microsoft Outlook 2010.

Microsoft Office 2010 offer some powerful tools, using this tools you can create application. Using Microsoft Visual Basic for Applications (VBA) you can create your own application according to your need. These application can performer some specific task.

For creating application we can use

  • VBA host of Excel 2010
  • VBA host of PowerPoint 2010
  • VBA host of Word 2010

NOTE : OneNote 2010 is not a VBA host.

Code that we use in this application are given below

Public Sub PickerDialogDemo()

    Dim a As Office.PickerDialog
    a = Application.PickerDialog
    a.Title = "Select a user to e-mail"
    Dim dh As String
    dh = "{000CDF0A-0000-0000-C000-000000000046}"
    a.DataHandlerId = dh
    Dim pp As Office.PickerProperties
    pp = a.Properties
    Dim picp As Office.PickerProperty
    Dim pickerID As String
    pickerID = "SiteUrl"
    Dim spurl As String
    spurl = "http://my"
    picp = pp.Add(pickerID, spurl, _
        Office.MsoPickerField.msoPickerFieldText)
    Dim dr As Office.PickerResults
    dr = a.Show(True)
    If Not dr Is Nothing 
Then

        ' The user selected at least one item so the
        
' code will create a new MailItem.

        Dim nm As Outlook.MailItem
        nm = Application.CreateItem(olMailItem)
        nm.Subject = "PickerDialog Demo"
        Dim result As Office.PickerResult
        For Each result In dr
            If result.Type = "User" Then
                nm.Recipients.Add(result.DisplayName)
            End If
        
Next

        ' Validate the users' display names added to the list
        
' of mail recipients.

        nm.Recipients.ResolveAll()
        Dim mailInspector As Outlook.Inspector
        mailInspector = nm.GetInspector
        mailInspector.Display()
    
Else

        ' If you click Cancel, the code falls through here.

    End If
End Sub

Step for creating Application

Step 1 : Start MS Outlook 2010 :

p1.jpg
 

Step 2 : Using Alt + F11 Key Start Visual Basic for Applications (VBA) Window :

p1 (1).jpg
 

Step 3 : Select on Project 1 :

Clipboard022.jpg
 

Step 4 : Double Click on project 1 ==> Select Microsoft Outlook objects ==> Double click on Microsoft Outlook   objects ==> Select on ThisOutlookSession==> Right Click on  ThisOutlookSession and select View Code :

p1 (2).jpg
 

Step 5 : Write Code in Visual Basic for Applications (VBA) Window :

Clipboard14.jpg

Clipboard16.jpg
 

Step 6 : Run Application using F5 :

Step 7 : Macros window will open, Select Macros name and click on Run Button :

Clipboard18.jpg
 

Step 8 : Output of Application :

Clipboard04.jpg

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.