Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2006

Tip: Looking for answers? Try searching our database.

Importing Outlook Contacts data into Word VBA?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bo Hansson - 02 Apr 2006 23:03 GMT
My environment is: Windows 2000 and upwards, Word 2000 and upwards.
Using Word VBA code - is it possible to import Outlook Contacts data into a
register in my Word VBA application?

/BosseH
zkid - 03 Apr 2006 01:58 GMT
Yes.

There are several ways, the easiest being through the address book if you
are just accessing the user's contacts and not delegated contacts from a
network.

From VBA help, type in GetAddress.

> My environment is: Windows 2000 and upwards, Word 2000 and upwards.
> Using Word VBA code - is it possible to import Outlook Contacts data into a
> register in my Word VBA application?
>
> /BosseH
zkid - 03 Apr 2006 17:52 GMT
Please go ahead and check out within VBA help the info. I sent you before for
GetAddress.  Then, see the following line within that info. [For a list of
the valid address book property names, see the AddAddress method.] and click
on AddAddress for a complete list of available fields you can use with
Graham's code shown below:

strCode = "<PR_GIVEN_NAME> <PR_SURNAME>" & vbCr
strCode = strCode & "<PR_COMPANY_NAME>" & vbCr
strCode = strCode & "<PR_POSTAL_ADDRESS>" & vbCr

'Let the user choose the name in Outlook

strAddress = Application.GetAddress("", strCode, False, 1, , , True, True)

The VBA help function has a multitude of information, not to mention code
you can actually copy and paste in your modules.

> Yes.
>
[quoted text clipped - 9 lines]
> >
> > /BosseH
Bo Hansson - 03 Apr 2006 18:36 GMT
Sorry "zkid" for confusing the audience. But I've experienced that helpful
members of the audience never turn back to a thread they obvious see as
completed, and my follow-up questions have not been paid any attention.
However, now I have two problems.

The first one is that following code does not return any information from
the following elements: "<PR_STREET_ADDRESS>", "<PR_POSTAL_CODE>" and
"<PR_LOCALITY>". All other elements are returned without problems.

strFnamn = "<PR_GIVEN_NAME>"
strEnamn = "<PR_SURNAME>"
strTel = "<PR_HOME_TELEPHONE_NUMBER>"
strEpost = "<PR_EMAIL_ADDRESS>"
strMobil = "<PR_CELLULAR_TELEPHONE_NUMBER>"
strGata = "<PR_STREET_ADDRESS>"
strPostNr = "<PR_POSTAL_CODE>"
strOrt = "<PR_LOCALITY>"

strCode = strFnamn & "$1" & strEnamn & "$2" & strTel & "$3" & strMobil &
"$4" & strEpost & "$5" & strGata & "$6" & strPostNr & "$7" & strOrt

strAddress = Application.GetAddress("", strCode, False, 1, , , True, True)

----------------------------------------------------------------------------
--
My second problem is that my attempt to add an adress fails. This is the
code:

Dim tagIDArray(0 To 8) As String
Dim valueArray(0 To 8) As String

tagIDArray(0) = "PR_DISPLAY_NAME"
tagIDArray(1) = "PR_GIVEN_NAME"
tagIDArray(2) = "PR_SURNAME"
tagIDArray(3) = "PR_HOME_TELEPHONE_NUMBER"
tagIDArray(4) = "PR_CELLULAR_TELEPHONE_NUMBER"
tagIDArray(5) = "PR_EMAIL_ADDRESS"
tagIDArray(6) = "PR_STREET_ADDRESS"
tagIDArray(7) = "PR_POSTAL_CODE"
tagIDArray(8) = "PR_LOCALITY"

valueArray(0) = cboTilltal.Text & " " & tbxEfternamn.Text
valueArray(1) = cboTilltal.Text
valueArray(2) = tbxEfternamn.Text
valueArray(3) = tbxFTelefon.Text
valueArray(4) = tbxFMobil.Text
valueArray(5) = tbxEpost.Text
valueArray(6) = tbxGata.Text
valueArray(7) = tbxPostNr.Text
valueArray(8) = tbxPostOrt.Text

Application.AddAddress TagID:=tagIDArray(), Value:=valueArray()

The result is a message saying that "It was not possible to add the address
to the private address book".

Hope again for your assistance.

/BosseH

> Please go ahead and check out within VBA help the info. I sent you before for
> GetAddress.  Then, see the following line within that info. [For a list of
[quoted text clipped - 26 lines]
> > >
> > > /BosseH
Jean-Guy Marcil - 03 Apr 2006 20:17 GMT
Bo Hansson was telling us:
Bo Hansson nous racontait que :

> Sorry "zkid" for confusing the audience. But I've experienced that
> helpful members of the audience never turn back to a thread they
[quoted text clipped - 21 lines]
> strAddress = Application.GetAddress("", strCode, False, 1, , , True,
> True)

Your code, used as posted, worked on my machine.

Are you sure the info is entered in the appropriate fields in Outlook?
GetAddress extracts the info from the Address fields flagged as the mailing
address in Outlook. So you may enter info in the Home address fields, but if
the Business address is empty while being flagged as the mailing address,
GetAdress return empty handed..

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org 

Bo Hansson - 03 Apr 2006 20:37 GMT
Yes, as far as I can see the info is entered correctly. All is in the Home
address fields and Home is flgged as the mailing address.
I'm running Outlook 2000.

/BosseH

> Bo Hansson was telling us:
> Bo Hansson nous racontait que :
[quoted text clipped - 32 lines]
> the Business address is empty while being flagged as the mailing address,
> GetAdress return empty handed..
zkid - 03 Apr 2006 22:44 GMT
Hi Bo,

I find it very interesting that it is the last three items on your list that
do not come through (correct me if I'm wrong).

Instead of the Application... code below, try using this simplied version to
see if it works better for you for Office 2000:

strAddress = Application.GetAddress(AddressProperties:=strCode,
DisplaySelectDialog:=1)

> Yes, as far as I can see the info is entered correctly. All is in the Home
> address fields and Home is flgged as the mailing address.
[quoted text clipped - 40 lines]
> > the Business address is empty while being flagged as the mailing address,
> > GetAdress return empty handed..
Bo Hansson - 03 Apr 2006 23:23 GMT
Sorry "zkid", I get the same error!

/BosseH

> Hi Bo,
>
[quoted text clipped - 51 lines]
> > > the Business address is empty while being flagged as the mailing address,
> > > GetAdress return empty handed..
zkid - 03 Apr 2006 23:37 GMT
Do you actually get an error message?  Or are you just having the same
problem where it doesn't return the info.?

Would you humor us and use just those last three items in GetAddress and see
if the data is returned?  For instance:

strCode = strGata & "$6" & strPostNr & "$7" & strOrt
strAddress = Application.GetAddress(AddressProperties:=strCode,
DisplaySelectDialog:=1)

> Hi Bo,
>
[quoted text clipped - 51 lines]
> > > the Business address is empty while being flagged as the mailing address,
> > > GetAdress return empty handed..
Bo Hansson - 04 Apr 2006 00:01 GMT
Hi "zkid"

No, I do not get an error message - I can just see that no data is
.returned.

Have now tried to get just the last three items according to your
suggestion, and this returns a completely empty string. Not even the
separators ($6, $7) are included!

Thanks for your interest in this matter!

/BosseH

> Do you actually get an error message?  Or are you just having the same
> problem where it doesn't return the info.?
[quoted text clipped - 61 lines]
> > > > the Business address is empty while being flagged as the mailing address,
> > > > GetAdress return empty handed..
zkid - 04 Apr 2006 00:32 GMT
This is so strange.  Your code works fine for me.

It's as if the fields you are trying to retrieve are from a contact that
just doesn't have any data in those fields.  Please don't take offense, but
are you absolutely sure there's data there?

You can try placing the insert address icon on your main menu from Word's
customize menu and see what that derives.

From the view menu, select toolbars, customize.  Choose all commands.  Find
"Insert Address" - it's an open book icon.  Drag it to your main menu and
select okay.

Now click on the icon and choose the contact for which you need the data.  
See if it provides you with a complete address.  If it does, then there's
something missing from your code that isn't obvious to us.  If it doesn't
work, then the only other thing I can suggest is that you create a test
contact and insert information in all the necessary fields.  Then, try the
code again and see if it works.  If it does, then there's something wrong
with your existing contacts.

Go ahead and start a new thread - title it something like GetAddress not
providing all fields.  Make sure you provide your code from the get-go.  I
think you need some fresh blood on this one!

> Hi "zkid"
>
[quoted text clipped - 84 lines]
> address,
> > > > > GetAdress return empty handed..
Bo Hansson - 04 Apr 2006 09:37 GMT
I've already responded to this, but the reply has obviously disappeared in
the cyber space...

Once again - many thanks for all effort you have put into my problem.

Now I've also tried the "Insert Adress" button, both with the previous and a
newly created contact. Both returns just the name, no adress details!

I thought I had spoiled something in the Outlook application when I (after a
computer crash) tried to import contacts from the earlier computer setup. I
then got some strange messages about incompatibility. I have therefore
reinstalled my Office 2000 package, but my problem still remains.

I will follow your idea about a new thread. And - once more: MANY THANKS!

/BosseH

> This is so strange.  Your code works fine for me.
>
[quoted text clipped - 109 lines]
> > address,
> > > > > > GetAdress return empty handed..
zkid - 04 Apr 2006 18:38 GMT
Ah, you do indeed have corruption, then.  If InsertAddress doesn't work for
you, there is no code available that will cirrect your problem.

This is what you need to do.  

Instead of trying to export your contacts from a .pst, export them to an
Excel spreadsheet.  Take a look at the spreadsheet and make sure that the
addresses are there.  If not, these contacts are beyond repair and you will
need to re-enter the addresses.

Then, once again uninstall and re-install your Outlook setup.  Now import
the Excel spreadsheet contacts into your contact folder.

> I've already responded to this, but the reply has obviously disappeared in
> the cyber space...
[quoted text clipped - 136 lines]
> > > address,
> > > > > > > GetAdress return empty handed..
Graham Mayor - 03 Apr 2006 06:45 GMT
There is some example code for grabbing data from Outlook at
http://www.gmayor.com/Macrobutton.htm

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> My environment is: Windows 2000 and upwards, Word 2000 and upwards.
> Using Word VBA code - is it possible to import Outlook Contacts data
> into a register in my Word VBA application?
>
> /BosseH
Bo Hansson - 03 Apr 2006 10:48 GMT
Very good news, thanks a lot!

However, when testing the opportunities, I cannot extract address details
like  Street Address, Postal Code and City.
Have I missed something?

/BosseH

> My environment is: Windows 2000 and upwards, Word 2000 and upwards.
> Using Word VBA code - is it possible to import Outlook Contacts data into a
> register in my Word VBA application?
>
> /BosseH
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.