VBA in MS Outlook

metalguy90

Board Regular
Joined
Jul 18, 2003
Messages
106
Hello everyone,

I am trying to do a count in Outlook.
how do i create a macro in Outlook that will tell me how to many contacts are in the folder.

also, how do i tell the program how to save a contact as a vcard?

i am new to VBA for outlook. I have a pretty good understanding since i do a lot of programming in Excel, but i havent done much in Outlook, so i dont know all the methods and such.

all help is greatly appreciated! thanks!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi Metalguy,

If you like to know the number of contact in outlook, why not right-click the contacts folder and choose properties.
There you can choose "show total number of items"
if you select this and click OK Outlook will show the number just like you have with your Inbox when you have unread mail.( (3) or something)

can't help with the rest, sorry. :(

Greeting,
DaLiMan
 
Upvote 0
Hi,

metalguy90 said:
how do i create a macro in Outlook that will tell me how to many contacts are in the folder.

You can use this line of code:

Code:
MsgBox Application.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts).Items.Count

metalguy90 said:
also, how do i tell the program how to save a contact as a vcard?

There's all sorts of things you can do. This example will save of your contacts as an individual vCard file in C:\temp.

Code:
Sub SaveAllAsVCard()

    Dim MyContact   As ContactItem
    Dim ContactsFolder As MAPIFolder

    Set ContactsFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts)


    For Each MyContact In ContactsFolder.Items
        MyContact.SaveAs "C:\temp\" & MyContact.FullName & ".vcf", olVCard
    Next MyContact

End Sub

This example saves the contact with the name 'John Smith'

Code:
Sub SaveAsVCard()

    Dim MyContact   As ContactItem
    Dim ContactsFolder As MAPIFolder

    Set ContactsFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderContacts)
    
    Set MyContact = ContactsFolder.Items("John Smith")
    
    MyContact.SaveAs "C:\temp\John Smith.vcf", olVCard
    
End Sub

metalguy90 said:
i am new to VBA for outlook. I have a pretty good understanding since i do a lot of programming in Excel, but i havent done much in Outlook, so i dont know all the methods and such.

The Object Browser is your friend :)

HTH
Dan
 
Upvote 0

Forum statistics

Threads
1,221,525
Messages
6,160,326
Members
451,637
Latest member
hvp2262

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top