Results 1 to 14 of 14
  1. #1
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts

    GetAddress Method (Word XP / SP2)

    <img src=/S/yikes.gif border=0 alt=yikes width=15 height=15>

    Ay-yi-yi. I am working on some code using the GetAddress Method

    <pre> strAdd = Application.GetAddress("", "ContactLetterFormat", _
    UseAutoText:=True, DisplaySelectDialog:=1, SelectDialog:=2)</pre>



    However, this method only seems to return the first 255 characters. This restriction might work for a single address, but since letters often go to multiple recipients, I'm trying to get past it. I would also like to be able to have the user identify CCs and BCCs at the same time. The SelectDialog argument above will display To: and CC: -- if I change the number to a "3" it will also display BCC (an undocumented bit of info).

    So here's what I'm thinking I might be able to do:

    Use the GetAddress method to simply collect names.
    Parse them into separate To:, CC: and BCC: variables, with each name separated from the previous by VbCr.
    Then take each name in the To: variable and pass it to the GetAddress method with the Name:= argument, to collect the addresses for each of the To: recipients.

    This coding will undoubtedly come close to putting me in a coma, so I thought I'd ask if anyone saw any holes in it (or in the original code or character limitation, for that matter).

    Thanks,
    Kim

  2. #2
    New Lounger
    Join Date
    Nov 2003
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: GetAddress Method (Word XP / SP2)

    Hi Kim,

    I have been watching your posts w/ great interest, waiting for someone to reply -- as this is an issue that has been driving me NUTS. I'm replying to this thread of yours instead of the newest one hoping people will see you (WE!!!) still need a response!

    As a work around to the getaddress truncation, you can dump all the contacts into a list box that you've built and then pick multiple choices from that. There are instructions for this available here and there on the net -- at support.microsoft.com, if you search contcts/word/vba -- that sort of thing. If you need it, let me know I have a copy somewhere I can get to you.

    However, THAT solution is not acceptable IMO because it only pulls from the ONE MAIN CONTACT folder. What about contact sub folders, personal folders, and public folders?

    Sooooooooo....

    As a further tip -- I recently emailed an Outlook programmer-for-hire about this exact dilemna. And she suggested I look into the Outlook PickFolder method to let the user select the folder, then dump the contacts from the selected folder into a list box, and let them pick from there. This looks doable but I haven't had a chance to try it yet. HTH. If you DO dig in and figure this out -- I'd love to hear back from you...

    In my mind it would go somethink like this:
    From the Word template Open an instance of Outlook.
    Activate the pickfolder method
    dump the contact info for the folder the user picked into a list box
    Put the addresses the user selected into the document, a variable, whatever

    close the instance of outlook (Not sure exactly when to do this part)

    Good luck -- Please do keep me posted on your progress!
    Laura

  3. #3
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts

    Re: GetAddress Method (Word XP / SP2)

    Hi Laura,

    You know, I started out accessing Outlook objects directly. I built an array of all names in my chosen contact folder and displayed them in a listbox. At the same time, I also loaded various fields into the same array as well, then closed the instance of Outlook as soon as the list box (and array) was populated. Then when I chose my contact(s), the data was already in memory and it executed very quickly. But it's quite time consuming to load the fields into the array -- I have about 350 and it took anywhere from 15 to 30 seconds to complete loading, which is a long time for the user to wait.

    On the other hand, perhaps I could approach it as I was trying to do with the GetAddress method -- to populate the listbox with the display names only and close the instance of Outlook. Then once the user has chosen his To:, cc: and bcc: names, the code would open a new instance of Outlook and pull the address data only for the chosen To: recipients. I've done something like this with an Access database, so I can probably adapt that logic to this. I think the user is more likely to tolerate a little lag once they've chosen their contacts, plus I'd only be pulling the data they want, not all data -- which would make it more efficient.

    I'll give that a try and will be sure to let you know how it turns out.

    Thanks for the brain boost!
    Kim

  4. #4
    New Lounger
    Join Date
    Nov 2003
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: GetAddress Method (Word XP / SP2)

    Hi Kim,

    If you haven't already, check out this article: http://www.mvps.org/word/FAQs/InterD...OLFromWord.htm

    I never tested it, but they talk about using CDO when you get the data and how that is "very fast" compared to OLE.

    (Edited by HansV to make URL clickable - see <!help=19>Help 19<!/help>)

  5. #5
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts

    Re: GetAddress Method (Word XP / SP2)

    Wow Laura, it looks great. I'll try this today and report back on my results.

    Thanks,
    Kim

  6. #6
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts

    Re: GetAddress Method (Word XP / SP2)

    Hi Laura,

    Wow, I've spent a lot of time on this in the last couple of days. <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>

    Sadly, I just couldn't penetrate the mysteries of CDO. The code you identified for me was pretty hard to follow (admittedly so, per the author). However, I also looked up the KB articles to which he referred I couldn't get Microsoft's code to work. I kept getting an error in one line of code. I copied and pasted, to make certain I didn't suffer from fumble-fingers. Double-checked my references. No go. I gave up on it.

    So I went back to creating an instance of Outlook. (I don't know if this will work in other versions, but I'm using Office XP on Windows XP)

    In the UserForm_Initialize section I load my Outlook contact names and their EntryID (a unique numeric string that Outlook assigns when an item is saved or moved to another folder) into a list box. If there's only a company name with no contact name, I substitute the Company as I'm building my list. It takes between 8 and 10 seconds to populate this box with 350 names and I've added a little percentage counter at the bottom to show progress. I may try a couple of other ways to do this to tweak how the list appears.

    The user chooses from the list and shuffles names over to the TO, CC and BCC list boxes. The TOs have their EntryIDs copied over with them.

    Then, when the user clicks OK, the code goes back to each of the TO contacts using the GetItemFromID method. It grabs the contact associated with the EntryID and I can collect the addressing info I need and push it into a text box.

    I searched the MSDN Library site -- they have published a chapter of the book "Building Applications with Microsoft Outlook version 2002" by Randy Byrne and it was extremely helpful. I think I'm going to get the book.

    All in all, I'm pretty darned happy with it. I also think I can adapt it to multiple situations, including setting or changing folders. I'd like it if it went a wee bit faster, but isn't that always true?

    Kim (Whew!)

  7. #7
    New Lounger
    Join Date
    Nov 2003
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: GetAddress Method (Word XP / SP2)

    Kim,

    Thanks so much for all the tips on how you did this. It will probably be a few weeks before I get a chance to explore this further, but if I get anywhere with the CDO, I'll let you know.

    It surprises me that it is so hard to find info on how to do this -- With all the "Office Application's Integration" out there, it seems like such an obvious thing to want to do. <img src=/S/disappointed.gif border=0 alt=disappointed width=15 height=15>

    Laura

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: GetAddress Method (Word XP / SP2)

    Is CDO installed on your machine? It's perfectly possible to install Outlook without installing CDO. In fact, installing CDO requires extra work since it is a fairly well hidden option under Outlook. CDO is a wrapper around the MAPI calls, and if you think CDO is bad, take a look at MAPI some time.
    Charlotte

  9. #9
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts

    Re: GetAddress Method (Word XP / SP2)

    Hi Charlotte,

    Oh yeah, CDO is installed (v 1.21). I know because I added it as a reference to my project.

    I'm still cranky because GetAddress is so limited -- 255 characters returned means only about two and a half business addresses returned. Harumph.

    I'm with Laura -- getting info from Outlook into Word through automation is a no-brainer that MSFT should have accounted for. (I will leave you to fill in your own joke regarding MSFT and no brains...)

    Thanks,
    Kim

  10. #10
    New Lounger
    Join Date
    Nov 2003
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: GetAddress Method (Word XP / SP2)

    AND (just to pile on here...) Microsoft boasts having all these predesigned templates available, but none of them can pull in multiple names. Even if you add the Address book button to a toolbar, you're dealing with one contact at a time. It's like no one ever heard of a document referencing more than one person...

    <img src=/S/crybaby.gif border=0 alt=crybaby width=15 height=15>

  11. #11
    New Lounger
    Join Date
    Sep 2004
    Location
    Washington, District Of Columbia, USA
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: GetAddress Method (Word XP / SP2)

    One option to this problem is to create a function which shows the Address Book then returns the name and address information. I have some code which actually uses a button to find the name and address of the selected Address Book or Contact entry. It uses the GetAddress Function and does not take long since it is not populating a list box. The only downside to this is that it is using the users Address Book only. They can not select from another user's Address Book. The code is below

    Dim strName As String, strAddress As String, strCompany As String, strTitle As String

    On Error GoTo GetName_Error
    strName = Trim(Application.GetAddress( _
    AddressProperties:="<PR_DISPLAY_NAME_PREFIX>" & " " & "<PR_DISPLAY_NAME>", displayselectdialog:=1))
    strCompany = Application.GetAddress(AddressProperties:="<PR_COM PANY_NAME>", displayselectdialog:=2) & vbCrLf
    strTitle = Application.GetAddress(AddressProperties:="<PR_TIT LE>", displayselectdialog:=2) & vbCrLf
    strAddress = Application.GetAddress( _
    AddressProperties:="<PR_STREET_ADDRESS>" & vbCrLf & _
    "<PR_LOCALITY>" & ", " & "<PR_STATE_OR_PROVINCE>" & " " & "<PR_POSTAL_CODE>", _
    displayselectdialog:=2)
    NameAndAddress = strName & "|" & strAddress

    Exit Function

    GetName_Error:
    NameAndAddress = ""
    Exit Function

  12. #12
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts

    Re: GetAddress Method (Word XP / SP2)

    Wow, after all this time, someone has some input on this!

    I have since created a way of displaying all contacts directly from Outlook and choosing from a list. But I am intrigued by this approach.

    Unfortunately, I can't tell how to call the function. It looks as if you did not include all the coding (though I assume you are retrieving the NameAndAddress variable). How do you pass the intended name to the function? Or is this function intended to display the address book so you can choose the name?

    Thanks, Kim

  13. #13
    New Lounger
    Join Date
    Sep 2004
    Location
    Washington, District Of Columbia, USA
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: GetAddress Method (Word XP / SP2)

    This function, called from a command button, displays the Address Book so the user can choose the name. Once they click OK on the Address Book, it displays the name and address in two separate text boxes. I was looking at your post because I am working on some code which would allow someone to view and select from someone else's contacts. My problem has been working with the list selection. I would be interested in how you did that.

    Thanks Rhonda.

  14. #14
    5 Star Lounger kmurdock's Avatar
    Join Date
    Feb 2003
    Location
    Pacific Grove, California, USA
    Posts
    716
    Thanks
    10
    Thanked 34 Times in 28 Posts

    Re: GetAddress Method (Word XP / SP2)

    Hi Rhonda

    After very little fussing, I was able to return info from your code -- it was really very straightforward. Thanks.

    What I did to solve my problem was set a reference to Outlook so I could work with Outlook objects directly and not go through the Address Book, which was too limited for me. If you access Outlook without the Address Book in the way, you should be able to access any Outlook folder, including public or shared folders, and offer your users the ability to choose which list to use. But I didn't do that -- I only display the contacts in the user's own Contacts folder.

    There can definitely be a cost time-wise. The Address Book is almost instantaneous, whereas pulling Outlook contacts can take 2-3 up to 30 seconds to load into a list. It depends on the speed of the computer, what other things it's doing at the time, and whether it's going to pull contacts from someone else's .ost file and run into network traffic.

    Kim

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •