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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Outlook 2003 VBA Won't Run In Outlook 2010

Status
Not open for further replies.

Dawber

Technical User
Jun 29, 2001
86
GB
With the help and refinement of several posters on this forum, I created a macro in Outlook for inserting a date and time stamp on the front end of an e-mails subject, see below for code.

After updating to Outlook 2010 from 2003, the code which used to operate flawlessly now falls over on the "mItem.Save" line. I'm assuming the command has been modified or updated but would be grateful for any assistance in debugging?

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 = ActiveExplorer.CurrentFolder

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
[highlight #FCE94F]mItem.Save[/highlight]
End If

End If

Next j
    
Set mItem = Nothing
Set myFolder = Nothing

End Sub
]
 
hi,

Can't provide any direct assistance. However the Watch Window could be a mean of discovering the answer.

faq707-4594

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
The VB error message reads:


Run-time error '-2147221239 (80040109)':

The operation cannot be performed because the message has been changed.
 
The problem seems to be that Outlook 2010, unlike the 2003 version, will not accept the .save command to update a message subject, hence the error message. Is anybody aware of a method of changing a message subject in VBA that is accepted by Outlook 2010?
 
Is this run from the Outlook vba enviroment?
Why do you need to save? i.e. would .display or .send work for you?

Never knock on Death's door: ring the bell and run away! Death really hates that!
 
Thanks for responding, yes it is run in the Outlook VBA environment. The purpose of the macro is to time stamp the subject of each individual email in a folder (eg. the Inbox), so that they can be dragged and dropped into a hard drive / server / dvd folder and will then be listed in chronological order, dependent upon when they were sent.

As a result, neither .display (could potentially be hundreds of emails in Inbox) nor .send (if run in "Send" folder would resend all emails) would be suitable replacements for the original .save function.
 
Thanks i now understand what you're trying to do.
How about .SaveAs?

Never knock on Death's door: ring the bell and run away! Death really hates that!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top