Getting an Outlook HTMLBody into a Word document and save it as an XML file

H

Hollis D. Paul

I have an Outlook/Exchange Inbox folder with about 150 messages that I
want to stuff the HTMLBody property into a Word Document and save it as
a WordML document in a specific folder. All this using VBScript. I
have started with one of Helen Feddema's scripts (code31, I believe)
and have gotten it to make a restricted set based on category, and I
can get it to open a file for each item in the restricted set. I have
been given the following line as the way to get the Ritem.HTMLBody into
a Word Object, but if I execute it the documents disappear. Executing
the TypeText line blows them away also.

Will someone please give me a hint about how to get the Outlook
property into the document?

I also need help saving the document. If I set the strSaveName to
Name.XML, it saves it with an XML extension, but it has the usual Word
objects inside and it blows up when you try to open it. I need to get
it to convert to XML before I save it, I guess. Any help on this?


Function PrintDocs(o_item,strWordTemplate)

dim strSaveName

strSaveName = "C:\Temp\TestDoc"

'Open a new letter based on the selected template
appWord.Documents.Add strWordTemplate

' appWord.ActiveDocument.Selection.TypeText "This is my document"

' appWord.ActiveDocument.HTMLProject.HTMLProjectItems(1) =_
o_item.HTMLBody

'Write information to Word custom document properties
'Set prps = appWord.ActiveDocument.CustomDocumentProperties

appWord.Visible = True
appWord.Activate

MsgBox "Do we see a document?"

'Update fields in Word document and activate it
appWord.Selection.WholeStory
appWord.Selection.Fields.Update
appWord.Selection.HomeKey 6
' appWord.ActiveDocument.SaveAs strSaveName
'appWord.ActiveWindow.WindowState = 0

fLetterCreated = True

End Function



Hollis D. Paul [MVP - Outlook]
(e-mail address removed)
Using Virtual Access, Windows 2000 build 2600
http://search.support.microsoft.com/kb/c.asp?FR=0&SD=TECH&LN=EN-US

Mukilteo, WA USA
 
H

Hollis D. Paul

Hollis said:
Will someone please give me a hint about how to get the Outlook
property into the document?
Turns out to be absurdly simple:
appWord.Documents.Add strWordTemplate
appWord.Visible = True
Set MyDoc = appWord.ActiveDocument

MyDoc.Content.InsertAfter o_item.HTMLBody

Boom! It's there.


I also need help saving the document. If I set the strSaveName to
Name.XML, it saves it with an XML extension, but it has the usual Word
objects inside and it blows up when you try to open it. I need to get
it to convert to XML before I save it, I guess. Any help on this?
Still got this problem to do. SaveAs doesn't seem to take any arguments,
and I don't find a list of converters that handls XML. What to do?

Hollis D. Paul [MVP - Outlook]
(e-mail address removed)
Using Virtual Access, Windows 2000 build 2600
http://search.support.microsoft.com/kb/c.asp?FR=0&SD=TECH&LN=EN-US

Mukilteo, WA USA
 
J

Jean-Guy Marcil

Hollis D. Paul was telling us:
Hollis D. Paul nous racontait que :
Still got this problem to do. SaveAs doesn't seem to take any
arguments, and I don't find a list of converters that handls XML.
What to do?

"SaveAs" no arguments? Where did you look?

From the Word VBA help file:
expression.SaveAs(FileName, FileFormat, LockComments, Password,
AddToRecentFiles, WritePassword, ReadOnlyRecommended, EmbedTrueTypeFonts,
SaveNativePictureFormat, SaveFormsData, SaveAsAOCELetter, Encoding,
InsertLineBreaks, AllowSubstitutions, LineEnding, AddBiDiMarks)
???
Or are you referring to something else?

What Word version? the XML filter is a very recent addition.

2003 or maybe 2002, I can't remeber which!

In 2003 you can certainly do:

ActiveDocument.SaveAs "MyFile", wdFormatXML

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
H

Hollis D. Paul

Jean-Guy Marcil said:
"SaveAs" no arguments? Where did you look?
Yes, I certainly mis-spoke on that one. A quick look through the list
didn't show anything relating to XML. I went back and found I had to
look through the members of wdSaveFormat. I thought that was the magic
bullet, but it still didn't work. It finally dawned that I could not
use the Intellisense defs and had to look up the numeric value of
wdFormatHtml. It is 8. All works now.

Thanks for the response.

Hollis D. Paul [MVP - Outlook]
(e-mail address removed)
Using Virtual Access, Windows 2000 build 2600
http://search.support.microsoft.com/kb/c.asp?FR=0&SD=TECH&LN=EN-US

Mukilteo, WA USA
 

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