PDA

View Full Version : Insert userinfo from Global Address List (Outlook)



Rico
12-27-2006, 07:00 AM
Hi All

I am new with VBA, so I need some help J

I found this code on google and it works fine


Public Sub InsertAddressFromOutlook()
Dim strCode As String, strAddress As String
Dim iDoubleCR As Integer

'Set up the formatting codes in strCode
strCode = "<PR_GIVEN_NAME> <PR_SURNAME>" & vbCr & "<PR_TITLE>" _
& vbCr & "<PR_COMPANY_NAME>" & vbCr & "<PR_POSTAL_ADDRESS>" & vbCr

'Display the 'Select Name' dialog, which lets the user Choose
'a name from their Outlook address book
strAddress = Application.GetAddress(AddressProperties:=strCode, UseAutoText:=False _
, DisplaySelectDialog:=1, RecentAddressesChoice:=True, UpdateRecentAddresses:=True)
'If user cancelled out of 'Select Name' dialog, quit
If strAddress = "" Then Exit Sub

'Eliminate blank paragraphs by looking for two carriage returns in a row
iDoubleCR = InStr(strAddress, vbCr & vbCr)
Do While iDoubleCR <> 0
strAddress = Left(strAddress, iDoubleCR - 1) & Mid(strAddress, iDoubleCR + 1)
iDoubleCR = InStr(strAddress, vbCr & vbCr)
Loop

'Strip off final paragraph mark
strAddress = Left(strAddress, Len(strAddress) - 1)
'Insert the modified address at the current insertion point
Selection.Range.Text = strAddress


End Sub



But is it possible to make the code, choose the current user (system user) instead of the user has to those from the dialog box.

I hope you can help me with this problem

lucas
12-27-2006, 07:49 AM
I added a line break to your code so it wouldn't scroll off of the screen. I also found while pasting it into a module that several lines show red in the vbe. It was caused by where you put your line breaks and I have corrected it for you in the post above.

strCode = "<PR_GIVEN_NAME> <PR_SURNAME>" & vbCr & _
"<PR_TITLE>" & vbCr & _
"<PR_COMPANY_NAME>" & vbCr & _
"<PR_POSTAL_ADDRESS>" & vbCr
and
strAddress = Left(strAddress, iDoubleCR - 1) & _
Mid(strAddress, iDoubleCR + 1)

I'm not much help on Word or Outlook but someone will come along soon with some advice on these issues.