PC Review


Reply
Thread Tools Rating: Thread Rating: 17 votes, 4.29 average.

Export to Word via XML

 
 
Steve
Guest
Posts: n/a
 
      20th Mar 2010
I am attempting to adapt Peter Vogel's code to output Access to word using
XML.
(http://msdn.microsoft.com/en-us/library/aa662941(office.11).aspx).

I have downloaded his sample .mdb file and tried it and I am getting the
following error when I try to open the XML document:

The XML file myWord.XML can not be opened because there are problems with
the content. Details: a text/xml declaration may only occur at the very
beginning of input error location: Line:3, column: 59145.

I have reproduced the vba code from the access subprocedure and a
(truncated) copy of the XML below. Any help would be greatly appreciated.

vba code in access:
Sub CreateWord()
Dim strWordDocument As String
strWordDocument = "<?xml version='1.0'?>" & _
"<w:wordDocument xmlns:w='" & _
"http://schemas.microsoft.com/" & _
"office/word/2003/2/wordml'>" & _
"<?mso-application progid='Word.Document'?>" & _
"http://schemas.microsoft.com/" & _
"office/word/2003/2/wordml'>" & _
"<w:body><w><w:r><w:t>" & _
"We have been very patient about your outstanding account, due since" & _
"</w:t></w:r><w:r><w:rPr><w:i w:val='on'/></w:rPr><w:t>" & _
"January 1, 1891</w:t></w:r><w:r><w:t>" & _
"We wish to advise you that if we haven't received full payment of the" & _
"</w:t></w:r><w:r><w:rPr><w:i
w:val='on'/></w:rPr><w:t>$200.00</w:t></w:r>" & _
"<w:r><w:t>within the next 30 days, we will seek legal
action.</w:t></w:r>" & _
"</w></w:body></w:wordDocument>"

Dim fl As Scripting.FileSystemObject
Dim txt As Scripting.TextStream

Set fl = New Scripting.FileSystemObject
Set txt = fl.OpenTextFile("C:\Documents and
Settings\ssesla\Desktop\MyWord.XML", _
ForAppending, True)
txt.Write strWordDocument
txt.Close

Set txt = Nothing
Set fl = Nothing

End Sub



Here is the XML file that will not open in Word:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?mso-application progid="Word.Document"?>
<w:wordDocument
xmlns:w="http://schemas.microsoft.com/office/word/2003/wordml"
xmlns:v="urn:schemas-microsoft-com:vml"
xmlns:w10="urn:schemas-microsoft-comffice:word"
xmlns:sl="http://schemas.microsoft.com/schemaLibrary/2003/core"
xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
xmlns:wx="http://schemas.microsoft.com/office/word/2003/auxHint"
xmlns="urn:schemas-microsoft-comfficeffice"
xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"
xmlns:wsp="http://schemas.microsoft.com/office/word/2003/wordml/sp2"
w:macrosPresent="no" w:embeddedObjPresent="no" wcxPresent="no"
xml:space="preserve"><w:ignoreElements
w:val="http://schemas.microsoft.com/office/word/2003/wordml/sp2"/><oocumentProperties><o:Author>ssesla</o:Author><o:LastAuthor>ssesla</o:LastAuthor><o:Revision>2</o:Revision><o:TotalTime>0</o:TotalTime><o:Created>2010-03-20T17:34:00Z</o:Created><o:LastSaved>2010-03-20T17:34:00Z</o:LastSaved><o:Pages>1</o:Pages><o:Words>0</o:Words><o:Characters>0</o:Characters><o:Company>Children's
Hospital and Regional Medical
Center</o:Company><o:Lines>1</o:Lines><o:Paragraphs>1</o:Paragraphs><o:CharactersWithSpaces>0</o:CharactersWithSpaces><o:Version>11.0000</o:Version></oocumentProperties><w:fonts><w:defaultFonts
w:ascii="Times New Roman" w:fareast="Times New Roman" w:h-ansi="Times New
Roman" w:cs="Times New
Roman"/></w:fonts><w:styles><w:versionOfBuiltInStylenames
w:val="4"/><w:latentStyles w:defLockedState="off"
w:latentStyleCount="156"/><w:style w:type="paragraph" w:default="on"
w:styleId="Normal"><w:name w:val="Normal"/><w:rPr><wx:font wx:val="Times New
Roman"/><w:sz w:val="24"/><w:sz-cs w:val="24"/><w:lang w:val="EN-US"
w:fareast="EN-US" w:bidi="AR-SA"/></w:rPr></w:style><w:style
w:type="character" w:default="on" w:styleId="DefaultParagraphFont"><w:name
w:val="Default Paragraph Font"/><w:semiHidden/></w:style><w:style
w:type="table" w:default="on" w:styleId="TableNormal"><w:name w:val="Normal
Table"/><wx:uiName wx:val="Table Normal"/><w:semiHidden/><w:rPr><wx:font
wx:val="Times New Roman"/></w:rPr><w:tblPr><w:tblInd w:w="0"
w:type="dxa"/><w:tblCellMar><w:top w:w="0" w:type="dxa"/><w:left w:w="108"
w:type="dxa"/><w:bottom w:w="0" w:type="dxa"/><w:right w:w="108"
w:type="dxa"/></w:tblCellMar></w:tblPr></w:style><w:style w:type="list"
w:default="on" w:styleId="NoList"><w:name w:val="No
List"/><w:semiHidden/></w:style></w:styles><w:docPr><w:view
w:val="print"/><w:zoom
wercent="90"/><w:displayBackgroundShape/><w:doNotEmbedSystemFonts/><w:attachedTemplate
w:val=""/><w:defaultTabStop
w:val="720"/><wunctuationKerning/><w:characterSpacingControl
w:val="DontCompress"/><wptimizeForBrowser/><w:validateAgainstSchema/><w:saveInvalidXML
w:val="off"/><w:ignoreMixedContent w:val="off"/><w:alwaysShowPlaceholderText
w:val="off"/><w:compat><w:breakWrappedTables/><w:snapToGridInCell/><w:wrapTextWithPunct/><w:useAsianBreakRules/><w:dontGrowAutofit/></w:compat><wsp:rsids><wsp:rsidRoot
wsp:val="008F0DE6"/><wsp:rsid wsp:val="00FF2C60"/><wsp:rsid
wsp:val="00FF38B8"/><wsp:rsid wsp:val="00FF44E5"/><wsp:rsid
wsp:val="00FF6AF0"/></wsp:rsids></w:docPr><w:body><wx:sect><w
wsp:rsidR="00D27B96" wsp:rsidRDefault="00D27B96"/><w:sectPr
wsp:rsidR="00D27B96"><wgSz w:w="12240" w:h="15840"/><wgMar w:top="1440"
w:right="1800" w:bottom="1440" w:left="1800" w:header="720" w:footer="720"
w:gutter="0"/><w:cols w:space="720"/><w:docGrid
w:line-pitch="360"/></w:sectPr></wx:sect></w:body></w:wordDocument><?xml
version='1.0'?><w:wordDocument
xmlns:w='http://schemas.microsoft.com/office/word/2003/2/wordml'><?mso-application
progid='Word.Document'?>http://schemas.microsoft.com/office/word/2003/2/wordml'><w:body><w><w:r><w:t>We
have been very patient about your outstanding account, due
since</w:t></w:r><w:r><w:rPr><w:i w:val='on'/></w:rPr><w:t>January 1,
1891</w:t></w:r><w:r><w:t>We wish to advise you that if we haven't received
full payment of the</w:t></w:r><w:r><w:rPr><w:i
w:val='on'/></w:rPr><w:t>$200.00</w:t></w:r><w:r><w:t>within the next 30
days, we will seek legal action.</w:t></w:r></w></w:body></w:wordDocument>


--
Steve
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what encoding does system.xml.xmldocument.save(string path) use to save the xml document if there is no <?xml... in the front of the xml document? Daniel Microsoft C# .NET 7 17th Mar 2007 11:29 AM
what encoding does system.xml.xmldocument.save(string path) use to save the xml document if there is no <?xml... in the front of the xml document? Daniel Microsoft Dot NET Framework 5 17th Mar 2007 10:11 AM
what encoding does system.xml.xmldocument.save(string path) use to save the xml document if there is no <?xml... in the front of the xml document? Daniel Microsoft Dot NET 1 15th Mar 2007 10:37 AM
Deserialize XML where XML may contain XML nick_nw Microsoft C# .NET 1 5th Jul 2006 11:32 AM
embed src=myxml.xml - xml = xml + xslt = svg - no display? Mike Grandmasion Windows XP Internet Explorer 0 12th Aug 2004 11:02 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:32 AM.