Outlook 2007 Contract Address

Status
Not open for further replies.

LMS

Senior Member
Outlook version
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"
 
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
 
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"
 
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
 
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"
 
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.
 
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"
 
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
 
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
 
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
 
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.
 
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 = ""
 
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= ""
 
Oops, you want to put the addresses in the Home address field, not business. Switch the homeaddress and business address fields in that code.
 
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.
Similar threads
Thread starter Title Forum Replies Date
D Outlook 2007 Recovering E-Mails Using Outlook 0
W Transfer Outlook 2016 autocomplete file to Outlook 2007 Using Outlook 1
C Outlook 2007 Removing then adding account restores junk email processing Using Outlook 0
S Outlook 2007 crash linked to gdiplus.dll Using Outlook 0
S Outlook 2007 - Automatic purge fail Using Outlook 0
J outlook 2007 doesn't let me choose which .pst to search Using Outlook 2
D Outlook 2007 vs. Outlook 2010 -- ToDo Bar Using Outlook 0
D Outlook 2007 on 365 Using Outlook.com accounts in Outlook 2
S Macro for other actions - Outlook 2007 Outlook VBA and Custom Forms 23
S Verwendung von Outlook 2007 Using Outlook 0
A Arthur needs help with 2007 Outlook e-mail Using Outlook.com accounts in Outlook 3
M PST import from Outlook 2007 to 2010 - Address Book contacts all in 1 group Using Outlook 4
S outlook 2007 calendar search Using Outlook 6
B Migrate Outlook 2007 to Office 365 Using Outlook 3
X I have met my waterloo trying to resolve embedded graphics problem with outlook 2007 and now 2016 Using Outlook 1
R Outlook 2007 only loads some appointments Using Outlook 0
C Move Outlook 2007 to new PC with Outlook 365 Using Outlook 3
J Outlook 2007 Hide Messages Option not Available Using Outlook 2
S Outlook 2007 Calendar instant search problem. Windows 7 Using Outlook 4
S Outlook 2007 Calendar instant search problem. Windows 7 Using Outlook 0
B Server errors Outlook 2007 Using Outlook 1
S Reboot of frozen windows7 results in changed outlook 2007 settings Using Outlook 1
S Outlook 2007 printing wrong email address at top of page Using Outlook 8
M Configure outlook 2007 to accept digital signatures Using Outlook 2
D Outlook 2007 crashes when opening an email Using Outlook 2
R New chap saying hello and needing advice on Outlook 2007 thumbnails Using Outlook 3
icacream From Outlook 2007 to 2016 ! Using Outlook 9
vodkasoda Object could not be found Error in Outlook 2007 Outlook VBA and Custom Forms 5
S Outlook 2007: Address Cards allow entering text! Why? Using Outlook 3
S View Appointment in Text Wrap in Outlook 2007 Month Calendar View Using Outlook 0
L Outlook 2007 Separate the Send/Receive functions Using Outlook 2
M Outlook 2007 Contacts Glitch: Creating a new email Using Outlook 1
C Move from Outlook 2007 Enterprise (MOE) to Outlook Pro plus 2007 Using Outlook 1
J reinstalling Outlook 2007 asking for user name & password Using Outlook 14
P outlook addin unloaded in office 2007 Using Outlook 0
B Fonts in Outlook 2007 Using Outlook 4
R Add Exchange Account to existing POP3 Outlook 2007 Profile Using Outlook 0
C out of space in file group Outlook 2007 Using Outlook 2
A Moving archived contents in Outlook 2007 back into working folders Using Outlook 0
P Outlook 2007 Email Categorization using VBA Outlook VBA and Custom Forms 1
M Unable to Configure Gmail Account in Outlook 2007 Using Outlook 1
R Outlook 2007 or 2010 - Lock Down Functionality Outlook VBA and Custom Forms 3
S Outlook 2007, windows 10 Font size Using Outlook 1
Diane Poremsky Manually create a POP3 account in Outlook 2007 Using Outlook 0
J Can Click to Drag Custom Form Field But Cannot Drop When Designing in Outlook 2007 Outlook VBA and Custom Forms 2
L Outlook 2007 Font Using Outlook 3
J Outlook 2007 connector and Windows 10 Using Outlook 3
R Outlook 2007 - Shared Accounts and Resources without Exchange Server Using Outlook 0
L Outlook 2007 - Macro Re Search Using Outlook 16
D Outlook (Office) 2007 & Windows 10 Pro Using Outlook 6

Similar threads

Back
Top