Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting the folder focus in Outlook VBA

Status
Not open for further replies.

Dawber

Technical User
Jun 29, 2001
86
0
0
GB
I use the following VBA code to incorporate the date at the beginning of each e-mail's subject in the Inbox. Is it possible to run the macro on the current folder (Inbox, Sent Items, Whatever), rather than naming a specific location?

Code:
Sub AddDateToSubject()

Dim mItem As Object
Dim oFolder As Object
Dim j As Long

Set myOlApp = CreateObject("Outlook.Application")
Set myNameSpace = myOlApp.GetNamespace("MAPI")
Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)

For j = myFolder.Items.Count To 1 Step -1

Set mItem = myFolder.Items.Item(j)

If TypeName(mItem) = "MailItem" Then

If Left(mItem.Subject, 12) <> Format(mItem.SentOn, "YYYYMMDDhhmm") Then
mItem.Subject = Format(mItem.SentOn, "YYYYMMDDhhmm") & " " & mItem.Subject
mItem.Save
End If

End If

Next j
    
Set mItem = Nothing
Set myFolder = Nothing

End Sub
 
Dawber,
Code:
Set myFolder = ActiveExplorer.CurrentFolder

Hope this helps,

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top