Change "File As" Macro

S

samearle

2 NEW ISSUES:


1. I need to create a macro or VB script that will go through all the
contacts in an Outlook 2003 contact file and change the File As field
to "COMPANY(LNAME, FNAME)" from however they are chosen now.


2. I've created a new contact form and published it, it has extra
fields that I need. How do I get it to be the default used in a contact

file when I creater a new contact, view a contact or import group of
contacts?


Thanks for all your help.


Sam
 
S

Sue Mosher [MVP-Outlook]

1) The code sample at http://www.outlookcode.com/d/code/convertfields.htm shows how to loop through the items in a folder and change property values. With a little help from the Object Browser to look up exact property names, you should be able to adapt it.

2) See http://www.outlookcode.com/d/newdefaultform. Note that Outlook doesn't support importing to a custom form. You'd have to write custom code or use a third-party application. See http://www.outlookcode.com/d/customimport.htm.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

samearle

UPDATE ON #2 above - I've figured out how to set the new form to the
default. By right clicking the Outlook 2003 contact folder, going into
properties, the change "when posting to this folder, use:" and
selecting the new form I've created.

Now, when I create a new contact, it uses the form I created with the
additional fields. Additionally, when I open that contact, I can see
these fields.

Trouble is, I imported a bunch of contacts into this folder and they
did not go into the new form, rather the old standard form. I open the
contact after imported and it is in the old form.

When I mapped the fields while importing, it didn't give me the new
fields of the new form (and yes, I named them all properly in their
properties when designing the form).

Thanks.

Sam
 
S

samearle

Yes, the code sample at
http://www.outlookcode.com/d/code/convertfields.htm does show me how to
take data imported into the User1, User2, etc... field and put the data
in my custom form field where I would like it to go.

However, I'm not sure how it loops? Does it go through every contact in
a folder and do it?

Additionally, I'm still not sure how to change the "File As" field.
Example: A contact in has a first name, last mane and company.
Currently, the "file as" field is set to First Name Last Name. I would
like it to be Company (Last name, First Name). It is an option that is
predifined in the field. I would like to change all contacts in a file
to "file as" this way from however they are "filed as" now.

Thanks,

Sam
 
S

Sue Mosher [MVP-Outlook]

As I said earlier, Outlook never imports to a custom form.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

Yes, it has a For Each ... Next loop.

Did you read the Notes section on the convertfields.htm page? It largely answers your question about FileAs.

When in doubt about the exact name of properties, check the object browser: Press ALt+F11 to open the VBA environment in Outlook, then press F2. Switch from <All Libraries> to Outlook to browse all Outlook objects and their properties, methods, and events. Select any object or member, then press F1 to see its Help topic.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

samearle

Thanks very much for your help, problem is I'm not very good at this. I
did read the notes to accomplish my file as issue. Would I write a
macro like bellow and run it on the contacts folder?

Item_Write
Item.FileAs = Item.CompanyName & vbCrLf & Item.LastName & ", " &
Item.FirstName

Would this essentially go though every contact in the file and change
the file as to COMPANY (First name, Last Name)???

thakns,

Sam
 
S

samearle

Yes, I did read the notes - unfortunatly I don't really get it. How
would this be accomplished?

Essentially all I want to do ishave a macro that opens a contact file
and changes all the File As files to COMPANY (LNAME, FNAME).

Would I write a macro that looks like this and run it on the file?
Would it go through and change all the File as to what i want?

Item_Write
Item.FileAs = Item.CompanyName & vbCrLf & Item.LastName & ", " &
Item.FirstName

Thanks for all your help.

Sam
 
S

Sue Mosher [MVP-Outlook]

The second statement below could be used in a macro that loops through a contacts folder and instantiates an Item object for each item. I've rewritten it with a continuation character to make it more readable in these forums:

Item.FileAs = Item.CompanyName & vbCrLf & _
Item.LastName & ", " & Item.FirstName

Such a loop is shown in the code example at http://www.outlookcode.com/d/code/convertfields.htm . Inside the For Each ... Next loop, there is code to change property values on each item and save each item. Your code to change the FileAs property would need to replace those other property change lines.

Your first statement isn't valid at all, BTW.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

samearle

It's not working. I'm not very good at this, so need help. I created a
Macro that tlooks like this and tried to run it:

Sub ChangeFileAs()
Item.FileAs = Item.CompanyName & vbCrLf & _
Item.LastName & ", " & Item.FirstName
End Sub

I got an error message that said "object required."

Thanks for any help.

Sam
 
S

Sue Mosher [MVP-Outlook]

The missing object is Item. You haven't told Outlook which item you want to change. And we don't know either. Are you trying to modify some code sample you've read about? If so, maybe you need to go back to that sample and try to understand just how it works. If you have specific questions, feel free to ask.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

samearle

Well, that was my interperetation of the code you gave me to change the
"file as" field for all the contacts in an outlook 2003 contacts file.

I tried to put it into a macro.

And yes, I've read all that you've given me.

Thnaks very much.

Sam
 
S

Sue Mosher [MVP-Outlook]

For those of us using a dedicated news reader, rather than a web site, it is very hard to follow a thread if you don't quote any of the earlier messages. Please show *all* the code you are currently using. IIRC, I pointed you toward the example at http://www.outlookcode.com/d/code/convertfields.htm and also gave you the code you'd need to change the FileAs property. I don't see that you've put those two together yet.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
S

samearle

I'm really don't know what you mean, "put those two together yet."

1.I did this to move imported data into custom fields -
http://www.outlookcode.com/d/code/convertfields.htm - and it worked
wonderfuly! Thanks.

2. Then I followed these instructions to change the "file as" field in
all the contacts to "Company (Last name, First Name)" -
http://www.outlookcode.com/threads.aspx?forumid=3&messageid=7833 - and
put the code into a new macro:

Sub ChangeFileAs()
Item.FileAs = Item.CompanyName & vbCrLf & _
Item.LastName & ", " & Item.FirstName
End Sub

Are you saying somehow I need to put #2 into #1?? If so, how?

Thanks,

Sam

"For those of us using a dedicated news reader, rather than a web site,
it is very hard to follow a thread if you don't quote any of the
earlier messages. Please show *all* the code you are currently using.
IIRC, I pointed you toward the example at
http://www.outlookcode.com/d/code/convertfields.htm and also gave you
the code you'd need to change the FileAs property. I don't see that
you've put those two together yet."
 
S

Sue Mosher [MVP-Outlook]

What is relevant to your scenario at the second URL is the syntax used to combine company and name information in the same way that Outlook does it in the UI. If you read the discussion, though, you'd see that the exact application does not apply your scenario. It is for use on a custom Outlook form. So, you need to put the two techniques together.

From the code at the first URL, you learned how to loop through all the items in a contacts folder and set the value of an Outlook property using this syntax:

objItem.MessageClass = "IPM.Contact.Custom"

From the example at the second URL, you learned how to make a File As that works like the one in the UI:

Item.FileAs = Item.CompanyName & vbCrLf & Item.LastName & ", " & Item.FirstName

objItem in the first statement and Item in the second statement both refer to an Outlook item. The syntax in the first statement, however, is the one relevant to your scenario. So, you need to change all the instances of Item to objItem and then include the FileAs statement inside the looping code that you already know.

Make sense now?
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Address book sort 3
File As 2
Contacts for mobile devices in Exchange 0
Begin a marketking campaign? 1
Contact form issue 2
New Letter to Contact 2
OL 2010 search contact not working correctly 1
Outlook Tasks 1

Top