VSTO Question: Looking for WORD Action Pane example that lists and select contacts from Outlook

Would really appreciate any help or guidence.

I want to have an Action Pane in Word that somehow allows the user to select a contact from the Outlook contacts and insert that information in different parts of the document.

Are there any examples of integrating contatcs and using the action pane

Thanks for any help,

VA




Answer this question

VSTO Question: Looking for WORD Action Pane example that lists and select contacts from Outlook

  • Eli.weiwang

    Thanks for the tip!

    I'll try my luck. The only problem is, that I am using Visual Basic and don't have a clue how to translate your code. If you know how the VB Code is written, I would be very thankfull.

    Greets

    Speedtriple


  • Galovesongs

    With gratitude!


    I am not a VB expert - but this should give you an idea how similar to two languages are for translation:


    And in the startup - I added:
    --------------------------------------

    Public Class ThisDocument

    Dim wordApplication As Word.Application

    Private Sub ThisDocument_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup

    Me.ActionsPane.Controls.Add(New AddressControl(Me.Application))

    End Sub

    Private Sub ThisDocument_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown

    End Sub

    End Class


    In the control, I overrode th NEW() to accept a parameter just like C# (I omitted to show the code you already wrote to show the contacts - just edit yours to use my passed variable)
    -----------------------------------------------------------------------------------------------------------------------

    Public Class AddressControl

    Private Sub AddressControl_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Dim app As Word.Application

    Public Sub New(ByVal appPassed As Word.Application)

    app= appPassed
    ' This call is required by the Windows Form Designer.
    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.

    End Sub
    Public Sub New()

    ' This call is required by the Windows Form Designer.
    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.

    End Sub
    End Class




  • Alex Guion

    Hi there,

    perhaps I can help a bit. I've done the same thing for a word template project. What I am doing is programmatically accessing the address book used in word. If you have outlook installed, then the address book accesses the default outlook contacts list. Note: if outlook is running then the contacts list is automatically displayed. If outlook is not running, then a dialog displays asking which profile should be used. The standard is automatically selected in the dialog.

    In my example I have an actions pane with a button "btnAdresse", which when clicked shows the outlook contacts list. After selecting the contact I return certain address details to a multiline textbox "txtEmpfang" on the actionspane, allowing the user to add or change details before inserting the whole address into the document. Yout could also insert the address details directly into bookmarks in the document if you wanted to.

    Here my code:

    Private Sub btnAdresse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdresse.Click

    Dim AddressProperties As Object

    Dim returnValue As String

    Dim appWord As Word.Application = New Word.Application

    AddressProperties = "{<PR_COMPANY_NAME>" & ControlChars.CrLf & "}{<PR_DEPARTMENT_NAME>" & ControlChars.CrLf & "}{<PR_DISPLAY_NAME_PREFIX> <PR_SURNAME>" & _

    ControlChars.CrLf & "}<PR_STREET_ADDRESS>" & ControlChars.CrLf & ControlChars.CrLf & "<PR_POSTAL_CODE> <PR_LOCALITY>"

    returnValue = appWord.GetAddress(, AddressProperties, False)

    txtEmpfang.Text = returnValue

    Me.txtBetreff.Focus()

    End Sub

    The AddressProperties such as <PR_COMPANY_NAME> are predefined properties. Unfortunately I had a very good URL where all of these properties were defined, but can't remember the link. Try Google. In the properties definition the " { } " brackets mean that if the information for this property is not present in the address, then the next property is accessed. For example, if a contact doesn't have a company name entered in outlook, then the first line of the returned address will begin with the department name. If the department name isn't available, then the first line will begin with the name prefix "sir, madam, etc." and the surname, and so on .... What this does is prevent empty line being returned in the address block.

    Unfortunately I cannot send you the whole vb project since I am still working on my solution. If you need further help, just let me know.

    PS: you might have noticed that some of the names for control don't quite conform to correct english grammer, this is because I am programming a german version, ie. for german users.

    Greets

    Speedtriple


  • Erik Meijer

    Thanks!

  • C K Legan

    Actually, you do not need an 'actions pane' example because what you want to do can be done in a variety implementations (winform, user control, etc.). What you are going to do is work with the Outlook OM programmatically to retreive contact names and display them. I have compiled a list of resources to get you going in using the Outlook OM and working with Outlook data:

    http://blogs.msdn.com/johnrdurant/archive/2005/12/07/vsto_outlook_resourcelist.aspx

    This is the road you want to go down. Implementing the solution in an actions pane is, for the most part, not unique. Once you retrieve the contact info and a contact is selected, you need to work the Word OM to pump the data into the doc:

    http://blogs.msdn.com/johnrdurant/archive/2005/12/16/word_developer_resources.aspx

    This should get you going in the right direction.

    John.



  • CentrixGuy

    The Blogs.msdn.com site is having some connection problems, the first time I checked
    http://blogs.msdn.com/johnrdurant/archive/2005/12/07/vsto_outlook_resourcelist.aspx
    it failed on a time out. A few minutes later it was back up again. So retry a couple of times if you can't get through the first time.

    You are right, a lot of the links are 'rescheduled'. To fix this you have to remove the part between:

    http://msdn.microsoft.com/ and /library/en-us/ ...

    example:
    http://msdn.microsoft.com/office/understanding/vsto/articles/default.aspx pull=/library/en-us/odc_vsto2005_ta/html/odc_vstooutlookcontactaddin.asp

    will be:
    http://msdn.microsoft.com/library/en-us/odc_vsto2005_ta/html/odc_vstooutlookcontactaddin.asp

    -= Maarten =-



  • Scott Simmer

    John,

    A lot of of your resource links don't point top anything except "not found". For example, on "http://blogs.msdn.com/johnrdurant/archive/2005/12/07/vsto_outlook_resourcelist.aspx " these two don't reach anything... as well as quite a few others...

    Create an Outlook Business Contact Assistant Add-in with Visual Studio Tools for Office by Naveen Yajaman and John Durant

    and

    Outlook the Way You Want It—Build Custom Outlook GUIs with WinForms & VSTO by Ty Anderson

    Any idea of what I can do to get these links



  • Stage

    Thanks - grateful for you help

  • Cicada

    Hello va2,

    glad to help. I used the New Application since I didn't find a syntax that works. I am actually a newbie to programming and am managing to wangle my way through all this .Net stuff. If you have a better method, please let me know.

    By the way, I found the link to all the address properties: http://www.slipstick.com/contacts/insword.htm

    Enjoy!


  • nuno vieira

    The articles on Devx have been retired. I am working to re-publish all of my articles that were on the Devx site on my company's web site. The Office Control Freak article has been published is available here:

    http://www.cogentcompany.com/Articles/BecomeanOfficeControlFreak/tabid/93/Default.aspx

    The Articles section of the site is a work in progress. Eventually all of the articles will be re-published here:

    http://www.cogentcompany.com/Articles/

    Thanks,

    Ty


  • SquidE

    For a newbie - you saved my life. Thanks.

    By creating a new instance of the application is slower and a resource waste. Since your code resides in a Word dcoument or Template - you can use the currently active applicaiotn object.

    Here is what I did

    1. In ThisApplication.cs I globally store the application object and pass it to an overridden constructor in my control

    Word.Application application = null;

    private void ThisDocument_Startup(object sender, System.EventArgs e)

    {

    application = this.Application;

    ActionsPane.Controls.Add(new AddressControl(application));

    }

    2) In my control, I overrode the CTOR and use it

    Word.Application app = null;

    public AddressControl(Word.Application passed_application)

    {

    app = passed_application;

    InitializeComponent();

    }

    private void GetAddress_Click(object sender, EventArgs e)

    {

    Object AddressProperties = new object();

    object returnValue = new object();

    addressProperties = "<PR_GIVEN_NAME> <PR_SURNAME>";

    object missing = Type.Missing;

    object boolfalse = false;

    object booltrue = true;

    object zero = 0;

    object one = 1;

    string result = app.GetAddress(ref missing, ref AddressProperties, ref boolfalse, ref one, ref zero, ref booltrue, ref booltrue, ref booltrue);

    Namelabel1.Text = result;

    }



  • msucre

    Thanks - That was helpful but some of the really important arcticles point to DEVX and they don't have the articles either :(



  • Martinavd

    Wow! Speedtriple, I am truly grateful to you! Thanks. This is exactly what I needed. I am started in the right direction - I had no idea that Word already had an interface to get to contacts and names - I thought I had to program Outlook from within Word.

    One follow-up. Since you are using this from within Word, any reason you chose to create a new word application object and not use the current one you are working in



  • Andreas Wolff

    One other thought... I didnt find any WORD or EXCEL Action Pane articles where it accesses anything in Outlook. Is there a particular article or example John was thinking of



  • VSTO Question: Looking for WORD Action Pane example that lists and select contacts from Outlook