Outlook 2007 Contract Address

Status
Not open for further replies.

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
The following macro/code that I run, adds the City, State and Zip Code to the Note field, and not the Address Field of the contact. So if I have a contact list that each has an address, but not the City, State and Zip Code, which is the same for all, how can we change this so the Outlook 2007 Contact form when I run the macro, goes to the address of the person, and below the first line, adds the City, State and Zip Code. That would be wonderful.

Dim Ins As outlook.inspector
Dim Document As Word.Document
Dim Word As Word.Application
Dim Selection As Word.Selection
Set Ins = Application.ActiveInspector
Set Document = Ins.WordEditor
Set Word = Document.Application
Set Selection = Word.Selection

Selection.HomeKey Unit:=wdLine
Selection.EndKey Unit:=wdLine
Selection.TypeParagraph
Selection.TypeText Text:="City, State 77001"
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
The following code puts the City, State and Zip Code in the Contact address, but not below the first line of the address...so what do we add so it puts it below the first line of the address:

Dim objApp As Application
Dim objNS As NameSpace
Dim objFolder As MAPIFolder

Dim objItem As Object
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")

On Error Resume Next
If TypeName(objApp.ActiveWindow) = "Inspector" Then
Set objItem = objApp.ActiveInspector.currentItem

objItem.UserProperties("Address Selected") = "City, State 77001"


objItem.Save
GoTo Leave
End If

Set objSelection = objApp.ActiveExplorer.Selection

For Each objItem In objSelection


objItem.UserProperties("Address Selected") = "City, State 77001"


objItem.Save

Next
Leave:
Set objItem = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I thought maybe you entered a witness protection program. :)

Use this format to enter the address (this is the mailing address field) - where you take the value in the field, add a line break and then the new data.
objItem.MailingAddress = objItem.MailingAddress & vbCrLf & "City, State 77001"
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
I have the first line in the contact address, and this did not had the next line..so speficially what to do please:

Sub Test3()

Dim objApp As Application
Dim objNS As NameSpace
Dim objFolder As MAPIFolder

Dim objItem As Object
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")

On Error Resume Next
If TypeName(objApp.ActiveWindow) = "Inspector" Then
Set objItem = objApp.ActiveInspector.currentItem

objItem.MailingAddress = objItem.MailingAddress & vbCrLf & "City, State 77001"


objItem.Save
GoTo Leave
End If

Set objSelection = objApp.ActiveExplorer.Selection

For Each objItem In objSelection


objItem.MailingAddress = objItem.MailingAddress & vbCrLf & "City, State 77001"


objItem.Save

Next
Leave:
Set objItem = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing
End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
First, are these existing contacts with something in the address field and the mailing address checkbox checked? If not, you'll need to use .businessaddress or .homeaddress.

If the first line is in a custom field, use that to construct the address - from your original example above:
objitem.businessaddress = objItem.UserProperties("Address Selected") & vbcrlf & "City, state Zip"
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
these are existing contacts with one line in the address field So not sure what to do as it is the standard address in the contact and the field of it is Address Selected.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Address Selected is a custom field you created? This is the format you'll use to add the city state zip line under the street line - I'm not sure what fields they are in so you'll need to fill that part in.
field-where-you-want-address = field-with-street & vbcrlf & "city, state zip"
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
This did it...thanks very very much:

Sub Test3()

Dim objApp As Application
Dim objNS As NameSpace
Dim objFolder As MAPIFolder

Dim objItem As Object
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")

On Error Resume Next
If TypeName(objApp.ActiveWindow) = "Inspector" Then
Set objItem = objApp.ActiveInspector.currentItem

objItem.UserProperties("Address Selected") = objItem.UserProperties("Address Selected") & vbCrLf & "City, State 77001"


objItem.Save
GoTo Leave
End If

Set objSelection = objApp.ActiveExplorer.Selection

For Each objItem In objSelection


objItem.UserProperties("Address Selected") = objItem.UserProperties("Address Selected") & vbCrLf & "City, State 77001"


objItem.Save

Next
Leave:
Set objItem = Nothing
Set objFolder = Nothing
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
It turns out that the regular address in all contacts is the business address and you have to change it form the droplist to home address....but since I added all the home addresses to the business address the default address, how can I convert the business addresses to the home address ? If create new fields for addresses, the fields are Home Address and Business Address, but the field for the default address is Address Selected, which is for home and business....so when I created the following to change it, it did not work....so is there a way to do it please?

Sub ConvertBusinessAddresstoHomeAddress()
Dim objApp As Application
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim objItem As Object
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
On Error Resume Next
If TypeName(objApp.ActiveWindow) = "Inspector" Then
Set objItem = objApp.ActiveInspector.currentItem
objItem.UserProperties("Home Address") = objItem.UserProperties("Business Address")

objItem.Save
GoTo Leave
End If
Set objSelection = objApp.ActiveExplorer.Selection
For Each objItem In objSelection

objItem.UserProperties("Home Address") = objItem.UserProperties("Business Address")

objItem.Save
Next
Leave:
Set objItem = Nothing
Set objFolder = Nothing

End Sub
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
To All if this Helps

I added to my contact form, then two additional fields of the Business Address and the Home Address, and the Business Address Display is TextBox50 and the Home Address Display is Textbox51, and whatever you put in the default areas of business and home, it automatically puts the same these fields...so I create the following code that moves the address from Business Address to the Home Address, and deletes the Business Address, and it all shows up in the default address area:

Sub ConvertBusinessAddresstoHomeAddress()
Dim objApp As Application
Dim objNS As NameSpace
Dim objFolder As MAPIFolder
Dim objItem As Object
Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
On Error Resume Next
If TypeName(objApp.ActiveWindow) = "Inspector" Then
Set objItem = objApp.ActiveInspector.currentItem
objItem.GetInspector.ModifiedFormPages("General").Controls("TextBox51").Text = objItem.GetInspector.ModifiedFormPages("General").Controls("TextBox50").Text
objItem.GetInspector.ModifiedFormPages("General").Controls("TextBox50").Text = ""
objItem.Save
GoTo Leave
End If
Set objSelection = objApp.ActiveExplorer.Selection
For Each objItem In objSelection

objItem.GetInspector.ModifiedFormPages("General").Controls("TextBox51").Text = objItem.GetInspector.ModifiedFormPages("General").Controls("TextBox50").Text
objItem.GetInspector.ModifiedFormPages("General").Controls("TextBox50").Text = ""
objItem.Save
Next
Leave:
Set objItem = Nothing
Set objFolder = Nothing

End Sub
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
It turns out that the regular address in all contacts is the business address and you have to change it form the droplist to home address....but since I added all the home addresses to the business address the default address, how can I convert the business addresses to the home address ? If create new fields for addresses, the fields are Home Address and Business Address, but the field for the default address is Address Selected, which is for home and business....so when I created the following to change it, it did not work....so is there a way to do it please?
That's why i used the mailingaddress field.

Do you want to put the addresses in the business field? My super-duper bulk contacts change can do it. This macro changes the phone numbers fields but you'd use the same method for the address field.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
I don't see a macro you mentioned.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Got it! So what do I change for the home address to get the address from the business address of the contact default field?


If .OtherTelephoneNumber <> "" Then
If .MobileTelephoneNumber = "" Then
.MobileTelephoneNumber = .OtherTelephoneNumber
.OtherTelephoneNumber = ""
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
I think this is the right logic - if there is a home address, then check to see if the business address field is empty. If it's empty set the business address to equal the home address and remove the address from the home address field.

If so - this should work -

If .homeaddress <> "" Then
If .businessaddress = "" Then
.businessaddress = .homeaddress
.homeaddress= ""
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Oops, you want to put the addresses in the Home address field, not business. Switch the homeaddress and business address fields in that code.
 

LMS

Senior Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Got it! but i want it to do it for one contact i open or select a list of contacts in a folder. Not just change all in the contact folder. So what do we adjust for that please?
 
Status
Not open for further replies.
Top