Adding a date to the Subject line in a rule

  • Thread starter Thread starter cableguy47905 via OfficeKB.com
  • Start date Start date
C

cableguy47905 via OfficeKB.com

I am wanting to create a rule with the action to add today's date to the
subject line before moving it to another folder.

Can I do this? If so, does anyone have any code that would get me started on
it? I have done some coding in Access, but I have never attempted in Outlook.


Any help would be appreciated.

Thanks,
Lee
 
This is how you incorporate VBA with an existing rule:

How to create a script for the Rules Wizard in Outlook:
http://support.microsoft.com/default.aspx?scid=KB;en-us;q306108

You still need the code to move the item and update it, but that's
relatively straightforward. Call MailItem.Move(MAPIFolder), where MAPIFolder
is a previously set variable to the destination folder. You either need to
"walk" the Namespace.Folders collection (eg. Namespace.Folders("Mailbox -
John Doe").Folders("Inbox").Folders("Subfolder")), or if you know the EntryID
value use that with the Namespace.GetFolderFromID method.

The subject line change is the easiest part - MailItem.Subject =
MailItem.Subject & " (" & Date & ")"
 
Once I add the date to the subject, then I want to move it to a Personal
folder that is not in my mailbox. Is this possible? I really have no idea
how I should label the path.
I had checked out the MS KB, but it didn't really have very indepth examples.
Thanks again for the help.
Lee
This is how you incorporate VBA with an existing rule:

How to create a script for the Rules Wizard in Outlook:
http://support.microsoft.com/default.aspx?scid=KB;en-us;q306108

You still need the code to move the item and update it, but that's
relatively straightforward. Call MailItem.Move(MAPIFolder), where MAPIFolder
is a previously set variable to the destination folder. You either need to
"walk" the Namespace.Folders collection (eg. Namespace.Folders("Mailbox -
John Doe").Folders("Inbox").Folders("Subfolder")), or if you know the EntryID
value use that with the Namespace.GetFolderFromID method.

The subject line change is the easiest part - MailItem.Subject =
MailItem.Subject & " (" & Date & ")"
I am wanting to create a rule with the action to add today's date to the
subject line before moving it to another folder.
[quoted text clipped - 6 lines]
Thanks,
Lee
 
Yup, you can still move the message to another data file. Every loaded .pst
is like a top-level folder in the Namespace.Folders collection. So your
first .pst will be in Namespace.Folders(1), your 2nd in Namespace.Folders(2),
etc. So you'd have to loop through the top level or find it by name
(Namespace.Folders("My Personal Folders File").Folders("My Root Folder").

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


cableguy47905 via OfficeKB.com said:
Once I add the date to the subject, then I want to move it to a Personal
folder that is not in my mailbox. Is this possible? I really have no idea
how I should label the path.
I had checked out the MS KB, but it didn't really have very indepth examples.
Thanks again for the help.
Lee
This is how you incorporate VBA with an existing rule:

How to create a script for the Rules Wizard in Outlook:
http://support.microsoft.com/default.aspx?scid=KB;en-us;q306108

You still need the code to move the item and update it, but that's
relatively straightforward. Call MailItem.Move(MAPIFolder), where MAPIFolder
is a previously set variable to the destination folder. You either need to
"walk" the Namespace.Folders collection (eg. Namespace.Folders("Mailbox -
John Doe").Folders("Inbox").Folders("Subfolder")), or if you know the EntryID
value use that with the Namespace.GetFolderFromID method.

The subject line change is the easiest part - MailItem.Subject =
MailItem.Subject & " (" & Date & ")"
I am wanting to create a rule with the action to add today's date to the
subject line before moving it to another folder.
[quoted text clipped - 6 lines]
Thanks,
Lee
 
Do you have an example that I might be able to use? So far I have:

Sub CustomMailMessageRule(Item As Outlook.MailItem)
Item.Subject = Item.Subject & " ( " & Date & " ) "
Item.Move(
End Sub


I know my personal folder is located : M:\Emails.pst
The folder within that would be "Emails to file away"
I also have my Archive folder that is listed just above the personal folder
in the tree and in the data file management tool.

Would you be able to help with all of that info?

Whenever I try to use NameSpace.something, it doesn't recognize the command.
I am really clueless when it comes to coding in here. I greatly appreciate
the help/bottle feeding.
Thanks,
Lee
Yup, you can still move the message to another data file. Every loaded .pst
is like a top-level folder in the Namespace.Folders collection. So your
first .pst will be in Namespace.Folders(1), your 2nd in Namespace.Folders(2),
etc. So you'd have to loop through the top level or find it by name
(Namespace.Folders("My Personal Folders File").Folders("My Root Folder").
Once I add the date to the subject, then I want to move it to a Personal
folder that is not in my mailbox. Is this possible? I really have no idea
[quoted text clipped - 23 lines]
 
Sure. Take a look at this:

Dim myNameSpace As Outlook.NameSpace
Dim myPST As Outlook.MAPIFolder
Dim myFolder As Outlook.MAPIFolder

Set myNameSpace = Application.GetNamespace("MAPI")
Set myPST = myNameSpace.Folders("My PST DISPLAY NAME")
Set myFolder = myPST.Folders("Emails to file away")

Just change "My PST DISPLAY NAME" to whatever the root of your .pst is
labelled as when you look at it fully expanded. The code also assumes that
the "Emails to file away" folder is a top-level folder within that .pst.

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


cableguy47905 via OfficeKB.com said:
Do you have an example that I might be able to use? So far I have:

Sub CustomMailMessageRule(Item As Outlook.MailItem)
Item.Subject = Item.Subject & " ( " & Date & " ) "
Item.Move(
End Sub


I know my personal folder is located : M:\Emails.pst
The folder within that would be "Emails to file away"
I also have my Archive folder that is listed just above the personal folder
in the tree and in the data file management tool.

Would you be able to help with all of that info?

Whenever I try to use NameSpace.something, it doesn't recognize the command.
I am really clueless when it comes to coding in here. I greatly appreciate
the help/bottle feeding.
Thanks,
Lee
Yup, you can still move the message to another data file. Every loaded .pst
is like a top-level folder in the Namespace.Folders collection. So your
first .pst will be in Namespace.Folders(1), your 2nd in Namespace.Folders(2),
etc. So you'd have to loop through the top level or find it by name
(Namespace.Folders("My Personal Folders File").Folders("My Root Folder").
Once I add the date to the subject, then I want to move it to a Personal
folder that is not in my mailbox. Is this possible? I really have no idea
[quoted text clipped - 23 lines]
Thanks,
Lee
 
Thanks again for all of your help.

This is what I have.

Sub CustomMailMessageRule(Item As Outlook.MailItem)

Dim myNameSpace As Outlook.NameSpace
Dim myPST As Outlook.MAPIFolder
Dim myFolder As Outlook.MAPIFolder

Set myNameSpace = Application.GetNamespace("MAPI")
Set myPST = myNameSpace.Folders("M:\Emails.pst")
Set myFolder = myPST.Folders("0 Emails to file away")

Item.Subject = Item.Subject & " ( " & Now() & " ) "
Item.Move(myFolder)
End Sub

It is like it is ignoring the script. I have th emacros enabled. It will do
all of the other actions.
First it looks to see if I am in the CC, if so it will flag it red, and then
read the script to date and move it to my folder. All it does is flag it. I
can still have it move to the folder if I choose that option, but it still
won't date it.

What am I doing wrong?

Thanks,
Lee
Sure. Take a look at this:

Dim myNameSpace As Outlook.NameSpace
Dim myPST As Outlook.MAPIFolder
Dim myFolder As Outlook.MAPIFolder

Set myNameSpace = Application.GetNamespace("MAPI")
Set myPST = myNameSpace.Folders("My PST DISPLAY NAME")
Set myFolder = myPST.Folders("Emails to file away")

Just change "My PST DISPLAY NAME" to whatever the root of your .pst is
labelled as when you look at it fully expanded. The code also assumes that
the "Emails to file away" folder is a top-level folder within that .pst.
Do you have an example that I might be able to use? So far I have:
[quoted text clipped - 27 lines]
 
Almost there! We don't want the file name of your .pst, we want the *display
name*! Make sure your .pst is expanded so you can see all of your folders -
click the Folder icon in the navigation pane so it shows "Folder List".
Whatever the label is for the root of your .pst is the display name.

You should also call Item.Save before you move it.

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


cableguy47905 via OfficeKB.com said:
Thanks again for all of your help.

This is what I have.

Sub CustomMailMessageRule(Item As Outlook.MailItem)

Dim myNameSpace As Outlook.NameSpace
Dim myPST As Outlook.MAPIFolder
Dim myFolder As Outlook.MAPIFolder

Set myNameSpace = Application.GetNamespace("MAPI")
Set myPST = myNameSpace.Folders("M:\Emails.pst")
Set myFolder = myPST.Folders("0 Emails to file away")

Item.Subject = Item.Subject & " ( " & Now() & " ) "
Item.Move(myFolder)
End Sub

It is like it is ignoring the script. I have th emacros enabled. It will do
all of the other actions.
First it looks to see if I am in the CC, if so it will flag it red, and then
read the script to date and move it to my folder. All it does is flag it. I
can still have it move to the folder if I choose that option, but it still
won't date it.

What am I doing wrong?

Thanks,
Lee
Sure. Take a look at this:

Dim myNameSpace As Outlook.NameSpace
Dim myPST As Outlook.MAPIFolder
Dim myFolder As Outlook.MAPIFolder

Set myNameSpace = Application.GetNamespace("MAPI")
Set myPST = myNameSpace.Folders("My PST DISPLAY NAME")
Set myFolder = myPST.Folders("Emails to file away")

Just change "My PST DISPLAY NAME" to whatever the root of your .pst is
labelled as when you look at it fully expanded. The code also assumes that
the "Emails to file away" folder is a top-level folder within that .pst.
Do you have an example that I might be able to use? So far I have:
[quoted text clipped - 27 lines]
Thanks,
Lee
 
I made that change. It still seems to ignore it.

Sub CustomMailMessageRule(Item As Outlook.MailItem)

Dim myNameSpace As Outlook.NameSpace
Dim myPST As Outlook.MAPIFolder
Dim myFolder As Outlook.MAPIFolder

Set myNameSpace = Application.GetNamespace("MAPI")
Set myPST = myNameSpace.Folders("Personal Folders")
Set myFolder = myPST.Folders("0 Emails to file away")

Item.Subject = Item.Subject & " ( " & Now() & " ) "
Item.Save
Item.Move (myFolder)
End Sub

Do I need to have something activated somewhere else? It doesn't error out,
it just ignores it. It is probably something simple that I have forgotten to
do.

Thanks,
Lee
Almost there! We don't want the file name of your .pst, we want the *display
name*! Make sure your .pst is expanded so you can see all of your folders -
click the Folder icon in the navigation pane so it shows "Folder List".
Whatever the label is for the root of your .pst is the display name.

You should also call Item.Save before you move it.
Thanks again for all of your help.
[quoted text clipped - 45 lines]
 
Ok, it looks like I can't run any other action with the script. So I
modified it so that it will also flag the message, date it, and then move it.
It does flag, and date it, but I still can't get it to move it just yet. It
must be the format that I am puting the name in it. I will get this worked
out, I just know it.

This is what I have.
Sub CustomMailMessageRule(Item As Outlook.MailItem)

Dim myNameSpace As Outlook.NameSpace
Dim myPST As Outlook.MAPIFolder
Dim myFolder As Outlook.MAPIFolder

Set myNameSpace = Application.GetNamespace("MAPI")
Set myPST = myNameSpace.Folders("Personal Folders")
Set myFolder = myPST.Folders("0 Emails to file away")

Item.FlagStatus = olFlagMarked
Item.Subject = Item.Subject & " ( " & Now() & " ) "
Item.Save
Item.Move (myFolder)
End Sub

Does my .pst folder have to be in a certain drive? How does it know where to
look for the actual .pst?

Thanks,
Lee
Almost there! We don't want the file name of your .pst, we want the *display
name*! Make sure your .pst is expanded so you can see all of your folders -
[quoted text clipped - 8 lines]
 
Okay, let's streamline the procedure to handle some errors that I suspect may
be occurring. The code doesn't care where on your file system the .pst is
stored - as long as it's loaded in Outlook and you know the display name, it
can be worked with using the Outlook Object Model.

Sub CustomMailMessageRule(Item As Outlook.MailItem)
On Error GoTo CustomMailMessageRule_Error

Dim myNameSpace As Outlook.NameSpace
Dim myPST As Outlook.MAPIFolder
Dim myFolder As Outlook.MAPIFolder

Set myNameSpace = Application.GetNamespace("MAPI")
Set myPST = myNameSpace.Folders("Personal Folders")

If myPST Is Nothing Then
MsgBox "The 'Personal Folders' folder cannot be located!!"
Exit Sub
End If

Set myFolder = myPST.Folders("0 Emails to file away")

If myFolder Is Nothing Then
MsgBox "The '0 Emails to file away' folder cannot be located!!"
Exit Sub
End If

Item.FlagStatus = olFlagMarked
Item.Subject = Item.Subject & " ( " & Now() & " ) "
Item.Save
Item.Move myFolder

On Error GoTo 0
Exit Sub

CustomMailMessageRule_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
CustomMailMessageRule of VBA Document ThisOutlookSession"
Resume Next
End Sub

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


cableguy47905 via OfficeKB.com said:
Ok, it looks like I can't run any other action with the script. So I
modified it so that it will also flag the message, date it, and then move it.
It does flag, and date it, but I still can't get it to move it just yet. It
must be the format that I am puting the name in it. I will get this worked
out, I just know it.

This is what I have.
Sub CustomMailMessageRule(Item As Outlook.MailItem)

Dim myNameSpace As Outlook.NameSpace
Dim myPST As Outlook.MAPIFolder
Dim myFolder As Outlook.MAPIFolder

Set myNameSpace = Application.GetNamespace("MAPI")
Set myPST = myNameSpace.Folders("Personal Folders")
Set myFolder = myPST.Folders("0 Emails to file away")

Item.FlagStatus = olFlagMarked
Item.Subject = Item.Subject & " ( " & Now() & " ) "
Item.Save
Item.Move (myFolder)
End Sub

Does my .pst folder have to be in a certain drive? How does it know where to
look for the actual .pst?

Thanks,
Lee
Almost there! We don't want the file name of your .pst, we want the *display
name*! Make sure your .pst is expanded so you can see all of your folders -
[quoted text clipped - 8 lines]
Thanks,
Lee
 
Eric, you are a genius. I am so grateful. This will save me so much work.
It does finally work and I do not get any errors. I really appreciate this.
This works so slick. You just have no idea how this will help me organize my
emails. Plus I learned a little more about coding in Outlook.

Thanks so much,
Lee
Okay, let's streamline the procedure to handle some errors that I suspect may
be occurring. The code doesn't care where on your file system the .pst is
stored - as long as it's loaded in Outlook and you know the display name, it
can be worked with using the Outlook Object Model.

Sub CustomMailMessageRule(Item As Outlook.MailItem)
On Error GoTo CustomMailMessageRule_Error

Dim myNameSpace As Outlook.NameSpace
Dim myPST As Outlook.MAPIFolder
Dim myFolder As Outlook.MAPIFolder

Set myNameSpace = Application.GetNamespace("MAPI")
Set myPST = myNameSpace.Folders("Personal Folders")

If myPST Is Nothing Then
MsgBox "The 'Personal Folders' folder cannot be located!!"
Exit Sub
End If

Set myFolder = myPST.Folders("0 Emails to file away")

If myFolder Is Nothing Then
MsgBox "The '0 Emails to file away' folder cannot be located!!"
Exit Sub
End If

Item.FlagStatus = olFlagMarked
Item.Subject = Item.Subject & " ( " & Now() & " ) "
Item.Save
Item.Move myFolder

On Error GoTo 0
Exit Sub

CustomMailMessageRule_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
CustomMailMessageRule of VBA Document ThisOutlookSession"
Resume Next
End Sub
Ok, it looks like I can't run any other action with the script. So I
modified it so that it will also flag the message, date it, and then move it.
[quoted text clipped - 29 lines]
 
Thank you Lee, it was my pleasure. It was nice to see someone be so patient
and not give up - I'm sure you'll be mastering the finer details of Outlook
programming in no time.

--
Eric Legault - Outlook MVP, MCDBA, MCTS (SharePoint programming, etc.)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


cableguy47905 via OfficeKB.com said:
Eric, you are a genius. I am so grateful. This will save me so much work.
It does finally work and I do not get any errors. I really appreciate this.
This works so slick. You just have no idea how this will help me organize my
emails. Plus I learned a little more about coding in Outlook.

Thanks so much,
Lee
Okay, let's streamline the procedure to handle some errors that I suspect may
be occurring. The code doesn't care where on your file system the .pst is
stored - as long as it's loaded in Outlook and you know the display name, it
can be worked with using the Outlook Object Model.

Sub CustomMailMessageRule(Item As Outlook.MailItem)
On Error GoTo CustomMailMessageRule_Error

Dim myNameSpace As Outlook.NameSpace
Dim myPST As Outlook.MAPIFolder
Dim myFolder As Outlook.MAPIFolder

Set myNameSpace = Application.GetNamespace("MAPI")
Set myPST = myNameSpace.Folders("Personal Folders")

If myPST Is Nothing Then
MsgBox "The 'Personal Folders' folder cannot be located!!"
Exit Sub
End If

Set myFolder = myPST.Folders("0 Emails to file away")

If myFolder Is Nothing Then
MsgBox "The '0 Emails to file away' folder cannot be located!!"
Exit Sub
End If

Item.FlagStatus = olFlagMarked
Item.Subject = Item.Subject & " ( " & Now() & " ) "
Item.Save
Item.Move myFolder

On Error GoTo 0
Exit Sub

CustomMailMessageRule_Error:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure
CustomMailMessageRule of VBA Document ThisOutlookSession"
Resume Next
End Sub
Ok, it looks like I can't run any other action with the script. So I
modified it so that it will also flag the message, date it, and then move it.
[quoted text clipped - 29 lines]
Thanks,
Lee
 
Back
Top