Visual Basic for Applications Samples

Sub FileAs_Company_FullName

' Change the FileAs field to contain the CompanyName followed by the FullName of the Contact

Set CurFolder = Application.ActiveExplorer.CurrentFolder

Set AllItems = CurFolder.Items

NumItems = CurFolder.Items.Count

MsgBox "Changing FileAs to Company & FullName: " & NumItems

'Loop through all of the items in the folder

For I = 1 to NumItems

Set CurItem = AllItems.Item(I)

' Test to see if the Message Class needs to be changed

If CurItem.FileAs <> CurItem.CompanyName Then

' Change the Message Class

CurItem.FileAs = CurItem.CompanyName & ", " & CurItem.FullName

' Save the changed item

CurItem.Save

'msgBox I &" " &CurItem.FileAs

End If

Next

MsgBox "Done."

End Sub

 

 

Sub Sent_Received_Date

' Copy the contents of the Sent field to be the same date and time as the Received field

Set CurFolder = Application.ActiveExplorer.CurrentFolder
Set AllItems = CurFolder.Items
NumItems = CurFolder.Items.Count

MsgBox "Copying Sent date to Received: " & NumItems

' Loop through all of the items in the folder
For I = 1 to NumItems
Set CurItem = AllItems.Item(I)

MsgBox I &" SentOn: " &CurItem.SentOn &" ReceivedTime: "& CurItem.ReceivedTime &"."

' Test to see if the date needs to be changed
If CurItem.ReceivedTime = CurItem.SentOn Then
' Do nothing if they are the same
Else
' Change the Received Time
CurItem.ReceivedTime =CurItem.SentOn

' Save the changed item
CurItem.Save
End If
Next

MsgBox "Done."

End Sub
 


Swapping the Business and Home address fields in Outlook

There is no choice on the Outlook standard interface to copy or move fields from one column to another.
Yet we can write and run a program to do this operation within minutes, automatically.