G
Greg Maxey
Hi,
I am using the following code to add a contact to OUTLOOK while working in
Word:
Sub myBtnMacro
Dim oApp As Outlook.Application
Dim oNspc As NameSpace
Dim oItm As ContactItem
Dim i As Long
Dim pStr As String
Set oApp = CreateObject("Outlook.Application")
Set oNspc = oApp.GetNamespace("MAPI")
Set oItm = oApp.CreateItem(olContactItem)
pStr = Selection.Text
pStr = Replace(pStr, Chr(13), Chr(11))
With oItm
.MailingAddress = Selection.Text
.Display
End With
Set oApp = Nothing
Set oNspc = Nothing
End Sub
The user selects the address portion of the text, runs the macro and the
OUTLOOK Create Contact dialog appears. The user types in any additional
information and Saves and Closes the Contact dialog.
My results are very sporadic and confusing. Sometimes the contact appears
in OUTLOOK contacts as soon as I finish adding it with Word and opening
OUTLOOK. Other times the contact doesn't apppear for several minutes and
after repeated tries to open and look for it in OUTLOOK. This morning I
tried to add two contacts. After several tries they never appeared in
OUTLOOK. I shut down my PC and restarted and tried to add another contact.
When I opened OUTLOOK none of the three contacts I had tried to add where
present. Then all of a sudden I hear bing, bing and the two previous
contacts appeared but never the third.
Obviously my code has a shortcoming. Can anyone please advise. Thanks.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Greg Maxey - Word MVP
My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org~~~~~~~~~~~~~~~~~~~~~~~~~~
I am using the following code to add a contact to OUTLOOK while working in
Word:
Sub myBtnMacro
Dim oApp As Outlook.Application
Dim oNspc As NameSpace
Dim oItm As ContactItem
Dim i As Long
Dim pStr As String
Set oApp = CreateObject("Outlook.Application")
Set oNspc = oApp.GetNamespace("MAPI")
Set oItm = oApp.CreateItem(olContactItem)
pStr = Selection.Text
pStr = Replace(pStr, Chr(13), Chr(11))
With oItm
.MailingAddress = Selection.Text
.Display
End With
Set oApp = Nothing
Set oNspc = Nothing
End Sub
The user selects the address portion of the text, runs the macro and the
OUTLOOK Create Contact dialog appears. The user types in any additional
information and Saves and Closes the Contact dialog.
My results are very sporadic and confusing. Sometimes the contact appears
in OUTLOOK contacts as soon as I finish adding it with Word and opening
OUTLOOK. Other times the contact doesn't apppear for several minutes and
after repeated tries to open and look for it in OUTLOOK. This morning I
tried to add two contacts. After several tries they never appeared in
OUTLOOK. I shut down my PC and restarted and tried to add another contact.
When I opened OUTLOOK none of the three contacts I had tried to add where
present. Then all of a sudden I hear bing, bing and the two previous
contacts appeared but never the third.
Obviously my code has a shortcoming. Can anyone please advise. Thanks.
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Greg Maxey - Word MVP
My web site http://gregmaxey.mvps.org
Word MVP web site http://word.mvps.org~~~~~~~~~~~~~~~~~~~~~~~~~~