Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2004

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Hollis D. Paul - 17 Nov 2004 04:48 GMT
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]
Hollis@outhousebythesound.com
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
Hollis D. Paul - 17 Nov 2004 20:28 GMT
In article
<VA.00001c80.03117845@obts-outlookdev.outlookbythesound.mukwoods>, Hollis
D. Paul wrote:
> 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]
Hollis@outlookbythesound.com
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
Jean-Guy Marcil - 17 Nov 2004 22:09 GMT
Hollis D. Paul was telling us:
Hollis D. Paul nous racontait que :

>> 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
[quoted text clipped - 5 lines]
> 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

Signature

Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org

Hollis D. Paul - 18 Nov 2004 00:51 GMT
> "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]
Hollis@outlookbythesound.com
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
Hollis D. Paul - 18 Nov 2004 00:17 GMT
In article
<VA.00001c80.03117845@obts-outlookdev.outlookbythesound.mukwoods>,
> I need to get
> it to convert to XML before I save it, I guess.  Any help on this?

The real problem is that thee is no Intellisense in VBScript.  So the
line that works is:

  MyDoc.SaveAs strSaveName, 8

Hollis D. Paul [MVP - Outlook]
Hollis@outlookbythesound.com
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.