' clear strTemp before setting a new value Set Selection = currentExplorer.Selection
Set currentExplorer = Application.ActiveExplorer
As written it increments the file number. This version of the macro applies to selected messages. ' removed the loop so it only works with the selected item The first lines picks up the Cancel button, the second checks the value and if empty, exits. To do this I changed Dim strFilenum As String to Dim strFilenum As Variant then added these the following lines.
This code sample adds the ability to cancel the entry. If you want the macro to work on selected or open messages, use the GetCurrentItem Function from work with open or selected items and the code below. You'll also need to remove the code that loops through all messages (and the MsgBox line). To run the macro on the selected message in the message list, replace the Set mail.
Rachid wanted to know how to use this macro with only the selected item. StrDate = Format(aItem.ReceivedTime, "mm-dd-yyyy")Ĭhange the subject of the selected or open message This version of the macro shows how to add the received date to the subject, with the date in a specific format. StrTemp = " " & aItem.Subject & " | " & F.FolderPath This code adds the code and folder path to the subject of every message in the folder. To do this, I needed to add 2 1/2 lines to the original macro: Dim and Set the folder variable, then add the folder name variable to the subject. Jason wanted to add a project number and the path where the message is stored. Sub SubjectNumbering(Item As Outlook.MailItem)Īdd a project number and the folder path to the subject To use, create a rule, choosing the run a script action and select this macro as the script. It saves the last used number to the registry for use in the next session. This sample is a Run a Script rule and will add a number to each message as they arrive. Run a Script Rule to add Sequential Numbers to subject Item.Subject = CStr(lRegValue) & " " & item.subject SaveSetting sAppName, sSection, sKey, lRegValue + 1 If lRegValue = 0 Then lRegValue = iDefault ' If the result is 0, set to default value. LRegValue = GetSetting(sAppName, sSection, sKey, iDefault) Sub objItems_ItemAdd(ByVal Item As Object) Set objItems = GetFolderPath("Direct ITR\Inbox").Items 'Set objFolder = objNS.GetDefaultFolder(olFolderInbox) Set objNS = Application.GetNamespace("MAPI") Private WithEvents objItems As Outlook.Items For more information on ItemAdd macros, see How to use an ItemAdd Macro. More information on Process items in a shared mailbox.
To test an ItemAdd macro, copy a message and paste in-place (Ctrl+C,V) or drag a message to the folder. You need the GetfolderPath function from Working with VBA and non-default Outlook Folders yo use it on folders not in your default mailbox. It can be used on folders in your default mailbox or in other mailboxes in your profile. This macro watches a folder and run the macro when a new message is added to it. Disable conversation view to see the updated subject lines on individual messages.Īlso, if the search results include sent messages, those subject lines will be updated too. Note: If you use this in Outlook 2010 and use Conversation view, the subject used for the conversation view won't change. When the macro is finished, a message will come up showing you how many items were changed.
Type your file number or keywords in then press OK or Enter. When you run the macro, a dialog box will come up asking for the file number (it accepts any text string). MsgBox iItemsUpdated & " of " & & " Messages Updated" StrFilenum = InputBox("Enter the file number") Set myolApp = CreateObject("Outlook.Application") I tested this code in Outlook 2010 and it should work in all older versions. Create a search folder to find all messages where the subject needs tagged then run the macro while viewing the search folder results. Using VBA to change the subject lineĬopy and paste the following code into the VB Editor. If there are just a few subject lines to edit, you can use in-cell editing to quickly paste the code into the subject.