Outlook has the built in ability to export contacts as vCards, but it will only do it one at a time. With the following vba script and a few bash commands, you can batch export each contact as a vCard and then combine the individual files into one vcard file.
Again, I needed to find the path to particular folder. This one was deep and not under my Inbox. So, updated the folder list function. It is now recursive and (very simply) shows the structure.
' Copyright under GPL by Mark Grimes ' list folders by poping up msg box windows Sub ListFolders() Dim objNS As NameSpace Dim objFolder Set objNS = Application.GetNamespace("MAPI") ListFromFolder objNS, "" Set objNS = Nothing End Sub Sub ListFromFolder(objFolderRoot, spaces As String) Dim objFolder As MAPIFolder For Each objFolder In objFolderRoot.Folders Debug.Print spaces + objFolder.Name If objFolder.Folders.count > 0 Then ListFromFolder objFolder, spaces + " " End If Next End Sub
I recently needed to walk through all the events in an Outlook calendar and make a change. Here is the simple code:
' Copyright under GPL by Mark Grimes ' list folders by poping up msg box windows Sub ResaveCalendarEntries() Dim objNS As NameSpace Dim objFolders, objFolder, objCalFolder Dim objCalEntry As AppointmentItem Dim count count = 0 Set objNS = Application.GetNamespace("MAPI") Set objCalFolder = objNS.Folders.item("Mailbox - MyMailBox").Folders.item("Calendar") ' This also works... ' Set objCalFolder = objNS.GetDefaultFolder(olFolderCalendar) For Each objCalEntry In objCalFolder.Items count = count + 1 Debug.Print count Debug.Print objCalEntry.Subject objCalEntry.Mileage = 1 objCalEntry.Save ' Exit Sub Next Set objNS = Nothing End Sub
I often find myself creating a Outlook contact from the signature in an email or some text in a work document. Rather than do it by hand each time, I have put together a few vba commands and a new vba class to parse the text on the clipboard and create a new contact from what it gathers.
To set it up, in ThisOutlookSession add:
Public Sub ParseClipboard() Dim Selection As DataObject Dim SelectionStr As String Set Selection = New DataObject Selection.GetFromClipboard SelectionStr = Selection.GetText CreateAddrFromStr SelectionStr End Sub
The spam filters that we use at work, process all the messages in a particular folder to train the filter. Rather than drag and drop messages, I use the following code to move the selected or active message into the target folder. For each of the public subs, I have a toolbar button which runs the code.
For the previous hack, I often had a hard time finding the correct folder to monitor. This bit of code will list all the top level folders for you.
' Copyright under GPL by Mark Grimes ' list folders by poping up msg box windows Private Sub ListFolders() Dim objNS As NameSpace Dim objFolders, objFolder Set objNS = Application.GetNamespace("MAPI") ' instantiate Items collections for folders we want to monitor Set objFolders = objNS.Folders For Each objFolder In objFolders MsgBox objFolder.Name Next Set objNS = Nothing End Sub
I often find myself creating a folder to store all the messages relating to a
particular project, and then wanting to forward any message placed in that
folder to one of my colleagues. This code, when placed in the
ThisOutlookSession module, takes care of the forwarding for me.
This code was derived from Sue Mosher’s article found in Windows & .Net Magazine.
``VBScript ‘ Copyright under GPL by Mark Grimes
Private WithEvents objEconomistItems As Items
‘ instantiate Items collections for folders we want to monitor Private Sub Application_Startup() Dim objNS As NameSpace Set objNS = Application.GetNamespace(“MAPI”)
Set objEconomistItems = objNS.GetDefaultFolder(olFolderInbox).Folders.Item("Mailing Lists").Folders.Item("Economist").Items Set objNS = Nothing
‘ disassociate global objects declared WithEvents Private Sub Application_Quit() Set objEconomistItems = Nothing End Sub
‘ Forward msg when new msg added to folder ‘ Prompt before sending Private Sub objEconomistItems_ItemAdd(ByVal Item As Object) Dim Response As Variant Dim myForward As Variant
Response = MsgBox("Forward message (" + Item.Subject + ") to Patrick & Josh?", vbYesNo) If Response = vbYes Then Set myForward = Item.Forward myForward.Recipients.Add "Patrick (E-mail)" myForward.Recipients.Add "Josh (E-Mail)" myForward.Send End If
End Sub ```
The following code worked for older versions of Outlook (2000 I believe), but does not work for newer versions. There used to be a junk button on the toolbar. The code effectively activated that button. I’m not sure how to do it in newer version of Outlook. I have actually given up on Outlook’s spam filtering and use SpamAssassian now. You might check out Wininspector to track down the right object.
If anyone figures out a solution, please email me know. I have had several people ask about this.
This code combines the frequently used steps of adding the senders of all selected e-mails to the Outlook “Junnk Sender’s List” and then moving the messages to the junk mail folder. I then create a toolbar button associated with this “macro.”