Retain formating from outlook email into word document?

  • Follow


As you can obviously tell from the script, I don't do this for a living.

The script takes the contents of an existing email in outlook, removes some 
stuff from the header and then writes it to a new MS Word document.  It is 
working.

The next step is to get it to preserve the HTML formatting of the original 
email message.  

I tried Changing "$messagebody = $m.body" and 
"$selection.TypeText($wordcontent[1])"  to "$messagebody = $m.htmlbody" and 
$selection.TypeText($messagebody)"  but it didn't work.

So I'm pretty much out of ideas about how to retain the html formatting when 
I import into word.



#OPEN OUTLOOK
$ol = new-object -comobject "outlook.application"

#GET THE RIGHT FOLDER
#folder name is hard coded for now and depends on outlook rule

$k = $ol.Session.Folders.Item(1).folders
foreach ($f in $k) {if ($f.name -eq "temp") {$b = $f} }

#START LOOP

foreach ($m in $b.Items) {
$messagebody = $m.body


#PARSE THE BODY - splits @ subject
# so saveas uses original subject as filename
$wordcontent =  $messagebody -split "Subject: "


#OPEN WORD and MAKE DOCUMENT and MAKE SELECTION
$word = new-object -comobject "word.application"
$document = $word.documents.add()
$selection = $word.selection

#make the document visible for testing
$word.visible = 1

#ADD CONTENT  
$selection.TypeText($wordcontent[1])

#Save document

$document.SaveAs()
$document.close()
$word.quit()

}    #END LOOP
0
Reply Utf 6/30/2010 10:09:10 PM


0 Replies
610 Views

(page loaded in 0.014 seconds)


Reply: