Discussion:
Cannot save updated message in in folder
(too old to reply)
unknown
2010-02-28 22:47:46 UTC
Permalink
I have written a macro for Outlook 2010 to modify received messages. I
works fine for all formats except rich text but that is the only place
I am using the Word Editor. I am modifying an open message and I see
the changes take place when using insertbefore. When I try to save the
message (objdoc.save) I get a prompt for a file name of
attachmentX.docx. The same thing happens if I try to run this macro on
Outlook 2007. I have coded this thing saven different ways and I still
wind up with the same problem. Anyone have any clues???
Ken Slovak - [MVP - Outlook]
2010-03-01 13:48:07 UTC
Permalink
With Outlook 2007 and 2010 you are using WordMail (WordEditor) always, there
is no choice and no other option.

Post the code you're using, otherwise no one could possibly have a clue
about your code or what it's doing.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
Post by unknown
I have written a macro for Outlook 2010 to modify received messages. I
works fine for all formats except rich text but that is the only place
I am using the Word Editor. I am modifying an open message and I see
the changes take place when using insertbefore. When I try to save the
message (objdoc.save) I get a prompt for a file name of
attachmentX.docx. The same thing happens if I try to run this macro on
Outlook 2007. I have coded this thing saven different ways and I still
wind up with the same problem. Anyone have any clues???
Black Pete
2010-03-02 15:48:40 UTC
Permalink
I thought the problem I was having was so basic that it would probably
be recognized as a basic mistake. However, here is a snippet..

Sub UpdteRichText(objItem)
Dim myitem As MailItem
Dim strFile As String
Dim objDoc As Word.Document
Dim objSel As Word.Selection
Dim objNS As Outlook.NameSpace
strFile = "Message goes here." & vbCrLf & vbCrLf
Set obJOL = Outlook.Application
Set objNS = obJOL.Session
Set objDoc = Application.ActiveInspector.WordEditor 'for open item
Set objDoc = objItem.GetInspector.WordEditor
Set objSel = objDoc.Windows(1).Selection
objSel.Move wdStory, -1
If objDoc.ProtectionType = wdAllowOnlyReading Then
objDoc.Unprotect
objDoc.Characters(1).InsertBefore strFile
objDoc.Save <========== Problem
Set objSel = Nothing
Set objDoc = Nothing
End Sub

When I attempt to do the save I get prompted for an external file name

On Mon, 1 Mar 2010 08:48:07 -0500, "Ken Slovak - [MVP - Outlook]"
Post by Ken Slovak - [MVP - Outlook]
With Outlook 2007 and 2010 you are using WordMail (WordEditor) always, there
is no choice and no other option.
Post the code you're using, otherwise no one could possibly have a clue
about your code or what it's doing.
Ken Slovak - [MVP - Outlook]
2010-03-02 19:59:38 UTC
Permalink
If you are trying to embed a file as an embedded attachment you are going
about it the wrong way. You should be using the Attachments.Add() method of
the item's Attachments collection. See the Help in the Object Browser on
that method for the arguments you need.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
Post by Black Pete
I thought the problem I was having was so basic that it would probably
be recognized as a basic mistake. However, here is a snippet..
Sub UpdteRichText(objItem)
Dim myitem As MailItem
Dim strFile As String
Dim objDoc As Word.Document
Dim objSel As Word.Selection
Dim objNS As Outlook.NameSpace
strFile = "Message goes here." & vbCrLf & vbCrLf
Set obJOL = Outlook.Application
Set objNS = obJOL.Session
Set objDoc = Application.ActiveInspector.WordEditor 'for open item
Set objDoc = objItem.GetInspector.WordEditor
Set objSel = objDoc.Windows(1).Selection
objSel.Move wdStory, -1
If objDoc.ProtectionType = wdAllowOnlyReading Then
objDoc.Unprotect
objDoc.Characters(1).InsertBefore strFile
objDoc.Save <========== Problem
Set objSel = Nothing
Set objDoc = Nothing
End Sub
When I attempt to do the save I get prompted for an external file name
On Mon, 1 Mar 2010 08:48:07 -0500, "Ken Slovak - [MVP - Outlook]"
Post by Ken Slovak - [MVP - Outlook]
With Outlook 2007 and 2010 you are using WordMail (WordEditor) always, there
is no choice and no other option.
Post the code you're using, otherwise no one could possibly have a clue
about your code or what it's doing.
Black Pete
2010-03-02 21:43:10 UTC
Permalink
I'm not trying to do anything with attachments. I am trying to insert
a line of text at the top of the message body in a received Rich Text
message that is open (inspector).

Note in code

objDoc.Characters(1).InsertBefore strFile <====

On Tue, 2 Mar 2010 14:59:38 -0500, "Ken Slovak - [MVP - Outlook]"
Post by Ken Slovak - [MVP - Outlook]
If you are trying to embed a file as an embedded attachment you are going
about it the wrong way. You should be using the Attachments.Add() method of
the item's Attachments collection. See the Help in the Object Browser on
that method for the arguments you need.
Ken Slovak - [MVP - Outlook]
2010-03-03 16:02:37 UTC
Permalink
Sorry, I glanced at the code and saw strFile and assumed text from a file.

I ran your macro code and had no problems in either Outlook 2007 or 2010. I
did get prompted for a file name of course since the Word doc had no file
name. I was prompted with "Message goes her1.docx".

To avoid that sort of thing for a previously unsaved Word doc you either
need to asign the doc a name using SaveAs() or you can just save the
underlying mail item if you don't want to save a document object to the file
system:

Application.ActiveInspector.CurrentItem.Save
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm
Post by Black Pete
I'm not trying to do anything with attachments. I am trying to insert
a line of text at the top of the message body in a received Rich Text
message that is open (inspector).
Note in code
objDoc.Characters(1).InsertBefore strFile <====
Black Pete
2010-03-03 23:49:56 UTC
Permalink
That is exactly what I tried to do originally, but it would not save
the open item. I would see the changes occur in the open item, but
the save would not make them permanent in the underlying message. When
(in testing) I let the macro run and then afterword I manaully close
the open item I am prompted with the "do you want to save the changes"
prompt. I don't want the User to get that prompt.

Let me show you the hokey way I got around this, Not what I consider
good programming. After the insert before statement I added:

SaveRTFBody = objItem.Body 'Save the message that Word has modified
objItem.Save 'Marks message saved but the Word changes are not saved
objItem.Body = SaveRTFBody 'Stuff the raw saved data into message body
objItem.Save ' This really saves the message changes to the underlying
message this time outside of Word of course.

Thank you for your time.

On Wed, 3 Mar 2010 11:02:37 -0500, "Ken Slovak - [MVP - Outlook]"
Post by Ken Slovak - [MVP - Outlook]
Sorry, I glanced at the code and saw strFile and assumed text from a file.
I ran your macro code and had no problems in either Outlook 2007 or 2010. I
did get prompted for a file name of course since the Word doc had no file
name. I was prompted with "Message goes her1.docx".
To avoid that sort of thing for a previously unsaved Word doc you either
need to asign the doc a name using SaveAs() or you can just save the
underlying mail item if you don't want to save a document object to the file
Application.ActiveInspector.CurrentItem.Save
Loading...