Outlook -> Word Oddity

M

Mark Eastom

A client of mine has run into a number of Outlook messages that users
managed to save as RTF files.

When the original message contained attachments those files are embedded
within the RTF file as rtf objects with a type of "Outlook.FileAttach".

If opened manually in MS-Word the attachments can be saved to disk with
their original file names.

When attempting (via a simple Visual Basic program) to save the files to
disk using Words automation Objects the Object property of the embedded
items OLEObject property is always "Nothing" so it can't be set to an
Outlook.Attachment object for saving to disk.


I made the mistake of attempting to use the ActivateAs method on the
OLEObject in an attempt to get the embedded objects to open as various types
with no success. Plus, it appears I've mucked up the registration of
MS-Words automation objects in the process.


I can parse through the RTF stream to grab the "objdata" and "class"
portions of the stream for each embedded object, but there doesn't appear to
be much useful documentation on MSDN (or elsewhere) on attempting to turn
said data and class into anything that might be able to allow retrieval of
the originally attached files.


Has anyone else run into anything along the lines of this and have clues /
suggestions?

Also, does anyone know of an easy way to re-register the Office 2000 objects
for MS-Word (or restore their original classid associations) without
uninstalling and reinstalling the whole thing and re-applying the service
packs?


I've tried opening MS-Incidents on these issues using my MSDN "free"
incidents, however, MS-Support hasn't bothered getting back to me regarding
my questions.
 
C

Cindy Meister -WordMVP-

Hi Mark,
If opened manually in MS-Word the attachments can be saved to disk with
their original file names.
By double-click, I take it?

See what happens if you use DoVerb.
When attempting (via a simple Visual Basic program) to save the files to
disk using Words automation Objects the Object property of the embedded
items OLEObject property is always "Nothing" so it can't be set to an
Outlook.Attachment object for saving to disk.
I made the mistake of attempting to use the ActivateAs method on the
OLEObject in an attempt to get the embedded objects to open as various types
with no success. Plus, it appears I've mucked up the registration of
MS-Words automation objects in the process.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jan 24 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
M

Mark Eastom

I need to uninstall / reinstall / reapply service packs on this machine for
MS-Office 2000 to get the automation objects working again after ActivateAs
totally mucked them up before I can attempt that.

However, I skipped over doing that originally because it seemed like it
would at best pop-up the same dialog box that double-clicking the attachment
in word brings up, which doesn't do much in terms of automating the process
of saving all attachments if the user needs to interact with the program for
each attachment to be saved.

I'll give it a shot though once I get the office automation interfaces
functional again.


Though, actually it would be nice to find more information related to
converting the "objdata" and "class" information stored in the RTF stream
into the original files.

Plus, its extremely disappointing that MS still hasn't bother to get in
touch with me regarding the incidents I've opened related to this. Their
"24 hours" for responding to the request for opening incidents has turned
into over a week so far..

Thanks.

---------------------------
 
C

Cindy Meister -WordMVP-

Hi Mark,
I need to uninstall / reinstall / reapply service packs on this machine for
MS-Office 2000 to get the automation objects working again after ActivateAs
totally mucked them up before I can attempt that.
Have you tried Help/Detect and Repair? (Sorry I didn't think to suggest that
before, but my mind was working on the OLE object question)
it seemed like it
would at best pop-up the same dialog box that double-clicking the attachment
in word brings up
I don't recall your mentioning any dialog box popping up?

Anyway, DoVerb should activate the object (like double-click) without your
needing to know the class or anything like that. That's why I suggested it :)
More tricky will be to know what automation commands to use once it's opened.
Does it open in Outlook, or Word?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jan 24 2003)
http://www.mvps.org/word

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
M

Mark Eastom

Cindy,

Repairing the office installation doesn't correct the situation.
Running word's command line switches to unregister / register doesn't
correct the situation.
Running the unregister swtich then trying to repair the installation doesn't
work.

I'm going to try to do the Office setup re-install rather than the repair,
then after that uninstall it followed by a complete reinstall.

I'm skeptical at this point that any of those will work.


The files being processed are RTF files that were originally either Outlook
MSG files or individual messages from an Outlook PST. These RTF files
can't (as far as I've been able to figure) be opened by any method using
Outlook to allow them to be recognized as Outlook messages. When the
original messages contained no attachments the RTF file are easy to process.
When the original messages did contain attachmentsthe RTF those attachments
are "converted" to embedded objects within the RTF stream. The "class" of
the objects is always "Outlook.FileAttach".

When these RTF files are opened in MS-Word, double-clicking that simply
launches the application that is associated with the embedded file. So even
though technically all of the embedded files are "Outlook File Attachments"
when the RTF is opened and the embedded objects are double-clicked the
native application for the attached file is launched. Which doesn't do
much good since the native application for some of the attachments may not
be installed on the machines that are attempting to "simply" save those
attachments to disk.

Right-clicking on the embedded objects within MS-Word within the RTF files
pops-up the context (doverb) context menu, that so far at least for all
types of attachments that I've seen to this point contains a "SaveAs" option
which when clicked does allow for the embedded object to be save to disk
using its original file name.

It seemed from that standpoint that the DoVerb call using automation within
VB would likely also pop-up the "SaveAs" dialog, which again, doesn't lend
itself to readily automating thes process of saving the original attachments
to disk. Especially when there are potentially hundreds of thousands of
these RTFs to be processed.

At that point I started doing research on trying to restore the file
attachments using their RTF "objdata" steam. The MS RTF related
documentation indicated that the API function "OleSaveToStream" is what is
used to generate the "objdata" stream. Which leads to the API function
"OleLoadFromStream", that says it requires the class and the streamed data
to be together in order to instantiate an object of the original type.
Unfortunately it doesn't go into any detail (nor does any other information
I've been able to find on MSDN or other resources) regarding how those two
pieces of data (or potentially other pieces that aren't documented as being
necessary) are to be contained in the combined stream in order for the
object to be instantiated. It also isn't clear as to which type of object
I ought to be attempting to instantiate since the RTF data lists the class
as being "Outlook.FileAttach", however, MS-Word "clearly" thinks that the
embedded object is really an MS-Word document for example.

On the other hand, if MS-Word is able to retrieve enough information about
the file attachment in order to perform an equivlent of a shellexecute on
the file to get the embedded objects native program to launch I'm hopeful
that I ought to be able to achieve a similar level of functionality to save
the native file to disk from the RTF stream.

Thanks for your suggestions Cindy,

Mark
 
M

Mark Eastom

A full uninstall, then installing office from scratch after than finally
made the Office Automation interfaces available again.

DoVerb action don't appear to be enumeratable with the ObjectVerbs for each
as suggested in MSDN, however, in playing with it I was able to get a few of
the DoVerb actions to run without errors. Essentially DoVerb(0) launches
the native application, DoVerb(1) is an "Open" action that gives the popup
dialog of Open or Save, DoVerb(2) launches the Save As dialog. There
doesn't appear to be a simple "Save" verb that would not requires user
interaction.

So it doesn't appear that DoVerb will be of much use for me at this point,
unless perhaps I want to try to get some sort of keypressing mechanism
working.

MS Support did leave a voice mail message for me, however, so now that I can
at least get back to dealing with functional code I can try to call them
back.

---------------------------
 
D

david epsom dot com dot au

A full uninstall, then installing office from scratch after than
made the Office Automation interfaces available again.

There is definitely something strange about the way automation
interacts with installation on windows now -- I note that changing
the automation server registration now has no effect, because OLE
now ignores the registration entry and instead uses an 'encrypted'
string that refers back to the installation package instead.

I've found no documentation on that...but I wish I had.

(david)
 
J

Jim Vita

Hi Mark,

We worked a case recently in which a customer was trying to do something
very similar to what you are trying to do. The solution we worked up for
that customer is as follows:

1) Open the RTF document
2) Select the whole document and copy it to the clipboard
3) Paste the document into an Outlook calendar item
4) Do a SaveAs for each attachment in the attachments collection

We used a calendar item because this did not require the explict creation
of a new item or document.

Hope this helps.

Thanks,

Jim

Jim Vita
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mark Eastom

I'll take a look at doing that.

I'm "assuming" that when you refer to using an Outlook calendar item that
you mean a instance of the "AppointmentItem" object?

That particular object doesn't appear to have anything that allows for
pasting anything into it form the Clipboard but I'll play around with it.

Thanks for the suggestion.
 
J

Jim Vita

Hi Mark,

Yes you'll retrieve the attachments from the AppointmentItem but you won't
paste directly into it. The method works like this.

1) Add an Explorer to the Outlook application object , using the default
folder with a type of olFolder Calendar
2) Display the explorer
3) "Execute" the paste command from the Explorer's CommandBars collection
4) Retrieve the appointment item from the CurrentItem of Outlooks
ActiveInspector
5) Interate the Attachments collection of the AppointItem
6) Call SaveAs on each attachment

I hope this is clear. Let me know how you fare.


Thanks,

Jim

Jim Vita
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.
 
M

Mark Eastom

Jim,

Thanks for your suggestion.

I had to work through some additional quirks to get the Paste control to
work, and the whole process is a bit obtuse, but it does appear to work for
the sample RTF files my client has given me to this point.

I'm going to give them a sample application to test on more of their RTF
files before I'm convinced that it is a completed solution though.

Another question - It there a property / method on the MS-Word Application
object that can be used to make it open the RTF files in a "silent" mode?

In a quick search I have not been able to find a means of doing that, bt
some of the RTFs cause "information" type messages to popup that need to be
closed before the automation process will continue. I don't need to know
that level of information so it would be nice to be able to not have them
popup rather than having to deal with closing them programmatically.

Thanks again for your assistance.

Mark
 
M

Mark Eastom

Jim,

It turns out that doing the attachment extraction in that manner sometmes
fails to be able to save all of the attachmetnts.

For example in a couple of files my client was testing it was able to
extract 6 of the 7 attachments, while in another case it was only able to
extract 1 of 3 attachments.

Unfortunately the files they're testing with are proprietary files from
their own clients so I'm trying to have them try to create an example email
with attachmentssaved as an RTF file that fails to have all of its
attachments extracted that I could pass along to you or someone else that
might be able to assist in coming up with a better solution to the problem.
 
M

Mark Eastom

The problem I was having with some of their files has been resolved.

For some reason it wasn't picking up email attachments that got placed at
the very end of the RTF message file, somehow what I was doing on the first
pass to select the entire document was missing those attachment.

I changed the code for selecting the entire document in MS-Word and it all
appears to work now.

Thanks much for you suggestions Jim!

Mark
 
D

docuity2

Mark said:
Jim,

Thanks for your suggestion.

I had to work through some additional quirks to get the Paste contro
to
work, and the whole process is a bit obtuse, but it does appear to wor
for
the sample RTF files my client has given me to this point.

Mark

Mark,

I am having hard time trying to implement Jim's advice to execute Past
command in Outlook.

Do you mind to share your code?

Thanks a lot.

Illy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top