• ActiveX Controls for Outlook (OfficeXP)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » ActiveX Controls for Outlook (OfficeXP)

    Author
    Topic
    #398325

    Hello.

    I was wondering if there are any ActiveX Controls that can be used to link VBA with Outlook Contacts. I would like to create a form that allows someone to select the Contacts in an address book.

    Viewing 1 reply thread
    Author
    Replies
    • #760609

      Are you sure you need an ActiveX solution? This code which originally came from Woody years ago shows a method of getting the contacts list displayed. You can probably hack this to do what you require. The GetAddress command is the one that does all the heavy lifting.

      Sub InsertAddressFromOutlook()
      Dim strCode, strAddress As String
      Dim iDoubleCR As Integer
      
      'Set up the formatting codes in strCode
      strCode = "" & vbCr
      strCode = strCode & "" & vbCr
      strCode = strCode & "" & vbCr
      strCode = strCode & ",  " & vbCr
      strCode = strCode & "" & vbCr
      
      'Let the user choose the name in Outlook
      strAddress = Application.GetAddress("", strCode, False, 1, , , True, True)
      'Strip away the final "Australia", if any
      If Right(strAddress, 10) = "Australia" & vbCr Then
        strAddress = Left(strAddress, Len(strAddress) - 10)
      End If
      
      'Eliminate blank lines by looking for two carriage returns in a row
      iDoubleCR = InStr(strAddress, vbCr & vbCr)
      While iDoubleCR  0
        strAddress = Left(strAddress, iDoubleCR - 1) & Mid(strAddress, iDoubleCR + 1)
        iDoubleCR = InStr(strAddress, vbCr & vbCr)
      Wend
      
      'Insert the modified address at the current insertion point
      Selection.TypeText strAddress
      End Sub
      • #760642

        This is very helpful. However, can the GetAddress method be used for multiple recipients, or just for selecting one person at a time?

        • #760672

          The GetAddress command has a SelectDialog argument which can allow this.

          If you explore the GetAddress help page you may find that modifying the key line of the code to
          strAddress = Application.GetAddress(“”, strCode, False, 1, 1, , True, True)
          allows you to select multiple recipients via a slightly different dialog.

          • #760696

            This has been most helpful. I have 2 more questions,

            a) if someone selects a distribution list from this dialog box, is there a (programmatic) way to list all the members of that group?
            how can you select names from a public or personal Contact folder? This dialog box only allows you to select from the Global Address List. (Perhaps I should post this question in the Outlook folder).

            Thanks!

            • #761160

              I don’t know about the first question but I suspect you can get at it because you can view the properties easily enough to see the members of the group. You may need to create a link to Outlook first though so this would require further code.

              On the address book question, I can select which address book to look in as shown in the screen capture. Do you not get this too?

            • #761162

              Andrew

              Thanks for that. Someone on the Outlook board directed me to Knowledge Base Article 287563 which I need to set up to be able to view Outlook Address Books. So I can now see the Address books.

              I am still interested to find out how to access the members of a distribution list, as I don’t really understand the Outlook model. If you know anything, that would be great.
              Marie-Therese

            • #761170

              There is a reply by JohnBF in the thread starting at post 323190 in the Outlook forum that may be helpful – look for the reply with VBA code.

            • #761171

              There is a reply by JohnBF in the thread starting at post 323190 in the Outlook forum that may be helpful – look for the reply with VBA code.

            • #761750

              Marie-Therese, reading through the thread I’m not clear on whether you are looking for street addresses or e-mail addresses. I don’t think Address Books include street addresses. If you want street addresses, you’ll need to work from the Contacts folders. As you process Contacts or AddressList Items, check the Class of each item to determine how to handle it (air code):

              If thisItem.Class = olDistributionList Then …
              ‘ loop thought DistList members by count as in the code Hans referred to
              Else If thisItem.Class = ‘ olContact if Contacts, or olAddressEntry if an AddressList Then …
              strAddress = ‘thisItem.BusinessAddress if Contact or thisItem.Address if AddressList, or other applicable Property

            • #761751

              Marie-Therese, reading through the thread I’m not clear on whether you are looking for street addresses or e-mail addresses. I don’t think Address Books include street addresses. If you want street addresses, you’ll need to work from the Contacts folders. As you process Contacts or AddressList Items, check the Class of each item to determine how to handle it (air code):

              If thisItem.Class = olDistributionList Then …
              ‘ loop thought DistList members by count as in the code Hans referred to
              Else If thisItem.Class = ‘ olContact if Contacts, or olAddressEntry if an AddressList Then …
              strAddress = ‘thisItem.BusinessAddress if Contact or thisItem.Address if AddressList, or other applicable Property

            • #761163

              Andrew

              Thanks for that. Someone on the Outlook board directed me to Knowledge Base Article 287563 which I need to set up to be able to view Outlook Address Books. So I can now see the Address books.

              I am still interested to find out how to access the members of a distribution list, as I don’t really understand the Outlook model. If you know anything, that would be great.
              Marie-Therese

            • #761161

              I don’t know about the first question but I suspect you can get at it because you can view the properties easily enough to see the members of the group. You may need to create a link to Outlook first though so this would require further code.

              On the address book question, I can select which address book to look in as shown in the screen capture. Do you not get this too?

          • #760697

            This has been most helpful. I have 2 more questions,

            a) if someone selects a distribution list from this dialog box, is there a (programmatic) way to list all the members of that group?
            how can you select names from a public or personal Contact folder? This dialog box only allows you to select from the Global Address List. (Perhaps I should post this question in the Outlook folder).

            Thanks!

          • #764737

            Andrew, I am having some trouble extracting the addresses from the strAddress string. Do you know what symbol or character delimits each address? I tried the CR and it almost works. But each entry has a “, ” preceding it. Also, is there a way to determine which addresses are CC, and which are TO?

            Thanks!

            • #764754

              Can you post the snippet of code you’re using to get the string? Then we can test it against our own address books and maybe give you an answer. (Or you could save the string to a file and post that, but I’m not sure it will remains unchanged in that process.)

            • #764762

              The code calls the GetAddress dialog with dialog of 2, which allows the user to enter multiple addresses

              sAddress = Application.GetAddress _
              (addressproperties:=cTags, _
              useautotext:=False, _
              displayselectdialog:=1, selectdialog:=2)

              The result looks like this
              Bear;Pooh;;;;;;;;;;;/;
              , Piglet;;;;;;;;;;;;;
              , Eeoor;;;;;;;;;;;

              Each address is separated with a CR and a “, “. Unfortunately, it limits the result to 255 characters, which is not very helpful. Also, there seems to be no way to determine if it is returning a CC or a TO address.

            • #764788

              Marie-Therese, I don’t have a problem with valid addresses, I get a return like this mix of addresses and unaddressed contracts:

              Michael Beatnik
              77 Drink Beer Drive,
              Nogales, CA 99999

              , Mary Jones
              ,
              , Ivy Walls
              ,

              Are you running your code in a country other then the US, where addressing conventions may be more flexible?

              (I hope Michael is adequately censored. grin)

            • #764802

              My address formatting may be different to yours. However, I think you have answered my question. The next address always begins with a CR “, “.

              There appears to be no way to distinguish between CC and TO addresses though, or is there? and your result is probably limited to 255 characters also, or is it?

              Thanks

            • #764844

              What is the format of cTags in your example? I tried this for a little test against my PAB:

              cTags = "" & vbCr & "" & vbCr & _
                      "" & Chr(254)

              This gave me pickthorn+comma+space between records within the To box, and pickthorn+comma+space between records within the CC box, but in between the two sets, there is no comma. Instead, I get pickthorn+vbCr. So to parse this, you could:

              Dim strAll() As String, strTo() As String, strCC() As String
              strAll = Split(sAddress, Chr(254) & vbCr)
              strTo = Split(strAll(0), Chr(254) & ", ")
              If UBound(strAll) > 0 Then
                  strCC = Split(strAll(1), Chr(254) & ", ")
              End If

              I can’t provide any assurances that this is the most efficient approach, but it does seem to work in my little test. Hope this helps.

            • #764845

              What is the format of cTags in your example? I tried this for a little test against my PAB:

              cTags = "" & vbCr & "" & vbCr & _
                      "" & Chr(254)

              This gave me pickthorn+comma+space between records within the To box, and pickthorn+comma+space between records within the CC box, but in between the two sets, there is no comma. Instead, I get pickthorn+vbCr. So to parse this, you could:

              Dim strAll() As String, strTo() As String, strCC() As String
              strAll = Split(sAddress, Chr(254) & vbCr)
              strTo = Split(strAll(0), Chr(254) & ", ")
              If UBound(strAll) > 0 Then
                  strCC = Split(strAll(1), Chr(254) & ", ")
              End If

              I can’t provide any assurances that this is the most efficient approach, but it does seem to work in my little test. Hope this helps.

            • #764846

              Regarding the 255 character limit, if you have the name, can’t you go back and retrieve the rest of the information in a separate pass? I suppose duplicate names could be a problem. Hmmm…

            • #765157

              We dont’ have any duplicate names, because if someone has the same name as another person, then there is a description of the area they work in (eg “Jscher (ABC)” and “Jscher (XYZ)”. This prevents us sending e-mails to the wrong person.

              I am struggling a lot with the Outlook Object Model. I have a lot of trouble writing simple code to lookup the address details of a name, or to look up all the names for a distribution list. I hope it starts to make some sense soon. If you have any sample code to lookup details, or members of the address list then this would be appreciated.

              One more comment, is that when the I use the “” tag in the GetAddress dialog box, it only ever returns the name and none of the other address details.

            • #765163

              > I am struggling a lot with the Outlook Object Model.

              Well, the dialog we’re working with is something of a throwback. Once you retrieve unique names from that dialog, you have a broad array of tools to look them up in Outlook. I guess that doesn’t make it any simpler, though.

              > One more comment, is that when the I use the “” tag in the GetAddress dialog box, it only ever returns
              > the name and none of the other address details.

              Sorry if my example misled you. Since you didn’t post your cTags definition, I just made up something that worked for my testing (Name, Phone, Email).

            • #765177

              Do you know of any posts on this site that demonstrate tools that I can use to retrieve the address details, when I have the name?

              Thank you very much for all your help.

            • #765244

              Not off the top of my head. But, if I recall correctly, GetAddress should allow this, using the Name parameter and no dialog. Does it work?

            • #765342

              Jscher, thank you so much! What a simple, and yet effective solution. You really are brilliant. bravo This effectively addresses the limitation of only 255 characters from the GetAddress dialog box.

              My last tricky question, is how do I return the names of all the people, if a distribution list is chosen from the GetAddress dialog box. I have been searching through the Outlook Object Model, and I can’t understand how to access the DistListItem. Any suggestions?

            • #765361

              Regarding the distribution list, I thought JohnBF posted some code for somebody on that just last month over on the Outlook board. But I’ll admit my memory isn’t what it once was.

            • #765367

              JohnBF pointed to this earlier in this thread. The code requires that you have the ContactItem selected. How do I find the Distribution List contact item? Do I have to search through every folder or AddressList to find it? or is there a quicker way.

            • #765378

              (Edited by jscher2000 on 08-Jan-04 15:56. Added the italicized clarification.)

              There’s a way to search a folder for the list. Check the VBA help for the Find method of Outlook’s Items collection. If the list isn’t in the default Contacts folder, it will take a bit more work to navigate to it (using the Folders(“First Level”).Folders(“Second Level”)…. method of specifying the path).

            • #765643

              I have been trying to follow this but it has gone way over my head because I don’t know Word’s Fields and Object Model at all. And I can see the value in the process you are developing, Marie-Therese. So if I can pester you both with some questions …

              GetAddress returns a string. If the user selects both DistList and Individual contact Items, are you saying that the process will have to be to parse each name from the string and then run each DistList name back through Get Address? How will you tell the difference between a DistList name string and a Contact string with an empty Address field?

              Is there another Word Method similar to GetAddress that is just ‘GetName’, which can then be run against the Contact Items?

              (I also don’t understand how you would run this kind of code against non-default Contact Folders.)

              Marie-Therese, I would really like to see you post all your related code as an attachment.

            • #766763

              Edited by HansV to move very long code to attachment.

              Here is the final code that enables you to select names from an address list, and it puts into the ListView control all the names, addresses, etc…When it looks for the members of the Distribution List, it does not limit it to the Global Address Book, but searches every address list until it finds it.

              Thank you to everyone who helped with this.

            • #766764

              Edited by HansV to move very long code to attachment.

              Here is the final code that enables you to select names from an address list, and it puts into the ListView control all the names, addresses, etc…When it looks for the members of the Distribution List, it does not limit it to the Global Address Book, but searches every address list until it finds it.

              Thank you to everyone who helped with this.

            • #765644

              I have been trying to follow this but it has gone way over my head because I don’t know Word’s Fields and Object Model at all. And I can see the value in the process you are developing, Marie-Therese. So if I can pester you both with some questions …

              GetAddress returns a string. If the user selects both DistList and Individual contact Items, are you saying that the process will have to be to parse each name from the string and then run each DistList name back through Get Address? How will you tell the difference between a DistList name string and a Contact string with an empty Address field?

              Is there another Word Method similar to GetAddress that is just ‘GetName’, which can then be run against the Contact Items?

              (I also don’t understand how you would run this kind of code against non-default Contact Folders.)

              Marie-Therese, I would really like to see you post all your related code as an attachment.

            • #765379

              (Edited by jscher2000 on 08-Jan-04 15:56. Added the italicized clarification.)

              There’s a way to search a folder for the list. Check the VBA help for the Find method of Outlook’s Items collection. If the list isn’t in the default Contacts folder, it will take a bit more work to navigate to it (using the Folders(“First Level”).Folders(“Second Level”)…. method of specifying the path).

            • #765368

              JohnBF pointed to this earlier in this thread. The code requires that you have the ContactItem selected. How do I find the Distribution List contact item? Do I have to search through every folder or AddressList to find it? or is there a quicker way.

            • #765362

              Regarding the distribution list, I thought JohnBF posted some code for somebody on that just last month over on the Outlook board. But I’ll admit my memory isn’t what it once was.

            • #765343

              Jscher, thank you so much! What a simple, and yet effective solution. You really are brilliant. bravo This effectively addresses the limitation of only 255 characters from the GetAddress dialog box.

              My last tricky question, is how do I return the names of all the people, if a distribution list is chosen from the GetAddress dialog box. I have been searching through the Outlook Object Model, and I can’t understand how to access the DistListItem. Any suggestions?

            • #765245

              Not off the top of my head. But, if I recall correctly, GetAddress should allow this, using the Name parameter and no dialog. Does it work?

            • #765178

              Do you know of any posts on this site that demonstrate tools that I can use to retrieve the address details, when I have the name?

              Thank you very much for all your help.

            • #765164

              > I am struggling a lot with the Outlook Object Model.

              Well, the dialog we’re working with is something of a throwback. Once you retrieve unique names from that dialog, you have a broad array of tools to look them up in Outlook. I guess that doesn’t make it any simpler, though.

              > One more comment, is that when the I use the “” tag in the GetAddress dialog box, it only ever returns
              > the name and none of the other address details.

              Sorry if my example misled you. Since you didn’t post your cTags definition, I just made up something that worked for my testing (Name, Phone, Email).

            • #765158

              We dont’ have any duplicate names, because if someone has the same name as another person, then there is a description of the area they work in (eg “Jscher (ABC)” and “Jscher (XYZ)”. This prevents us sending e-mails to the wrong person.

              I am struggling a lot with the Outlook Object Model. I have a lot of trouble writing simple code to lookup the address details of a name, or to look up all the names for a distribution list. I hope it starts to make some sense soon. If you have any sample code to lookup details, or members of the address list then this would be appreciated.

              One more comment, is that when the I use the “” tag in the GetAddress dialog box, it only ever returns the name and none of the other address details.

            • #764847

              Regarding the 255 character limit, if you have the name, can’t you go back and retrieve the rest of the information in a separate pass? I suppose duplicate names could be a problem. Hmmm…

            • #764803

              My address formatting may be different to yours. However, I think you have answered my question. The next address always begins with a CR “, “.

              There appears to be no way to distinguish between CC and TO addresses though, or is there? and your result is probably limited to 255 characters also, or is it?

              Thanks

            • #764789

              Marie-Therese, I don’t have a problem with valid addresses, I get a return like this mix of addresses and unaddressed contracts:

              Michael Beatnik
              77 Drink Beer Drive,
              Nogales, CA 99999

              , Mary Jones
              ,
              , Ivy Walls
              ,

              Are you running your code in a country other then the US, where addressing conventions may be more flexible?

              (I hope Michael is adequately censored. grin)

            • #764763

              The code calls the GetAddress dialog with dialog of 2, which allows the user to enter multiple addresses

              sAddress = Application.GetAddress _
              (addressproperties:=cTags, _
              useautotext:=False, _
              displayselectdialog:=1, selectdialog:=2)

              The result looks like this
              Bear;Pooh;;;;;;;;;;;/;
              , Piglet;;;;;;;;;;;;;
              , Eeoor;;;;;;;;;;;

              Each address is separated with a CR and a “, “. Unfortunately, it limits the result to 255 characters, which is not very helpful. Also, there seems to be no way to determine if it is returning a CC or a TO address.

            • #764755

              Can you post the snippet of code you’re using to get the string? Then we can test it against our own address books and maybe give you an answer. (Or you could save the string to a file and post that, but I’m not sure it will remains unchanged in that process.)

          • #764738

            Andrew, I am having some trouble extracting the addresses from the strAddress string. Do you know what symbol or character delimits each address? I tried the CR and it almost works. But each entry has a “, ” preceding it. Also, is there a way to determine which addresses are CC, and which are TO?

            Thanks!

        • #760673

          The GetAddress command has a SelectDialog argument which can allow this.

          If you explore the GetAddress help page you may find that modifying the key line of the code to
          strAddress = Application.GetAddress(“”, strCode, False, 1, 1, , True, True)
          allows you to select multiple recipients via a slightly different dialog.

      • #760643

        This is very helpful. However, can the GetAddress method be used for multiple recipients, or just for selecting one person at a time?

    • #760610

      Are you sure you need an ActiveX solution? This code which originally came from Woody years ago shows a method of getting the contacts list displayed. You can probably hack this to do what you require. The GetAddress command is the one that does all the heavy lifting.

      Sub InsertAddressFromOutlook()
      Dim strCode, strAddress As String
      Dim iDoubleCR As Integer
      
      'Set up the formatting codes in strCode
      strCode = "" & vbCr
      strCode = strCode & "" & vbCr
      strCode = strCode & "" & vbCr
      strCode = strCode & ",  " & vbCr
      strCode = strCode & "" & vbCr
      
      'Let the user choose the name in Outlook
      strAddress = Application.GetAddress("", strCode, False, 1, , , True, True)
      'Strip away the final "Australia", if any
      If Right(strAddress, 10) = "Australia" & vbCr Then
        strAddress = Left(strAddress, Len(strAddress) - 10)
      End If
      
      'Eliminate blank lines by looking for two carriage returns in a row
      iDoubleCR = InStr(strAddress, vbCr & vbCr)
      While iDoubleCR  0
        strAddress = Left(strAddress, iDoubleCR - 1) & Mid(strAddress, iDoubleCR + 1)
        iDoubleCR = InStr(strAddress, vbCr & vbCr)
      Wend
      
      'Insert the modified address at the current insertion point
      Selection.TypeText strAddress
      End Sub
    Viewing 1 reply thread
    Reply To: ActiveX Controls for Outlook (OfficeXP)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: