Export to Word via XML

S

Steve

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:p><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:p></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-com:eek:ffice: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:eek:="urn:schemas-microsoft-com:eek:ffice:eek:ffice"
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" w:eek:cxPresent="no"
xml:space="preserve"><w:ignoreElements
w:val="http://schemas.microsoft.com/office/word/2003/wordml/sp2"/><o:DocumentProperties><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></o:DocumentProperties><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
w:percent="90"/><w:displayBackgroundShape/><w:doNotEmbedSystemFonts/><w:attachedTemplate
w:val=""/><w:defaultTabStop
w:val="720"/><w:punctuationKerning/><w:characterSpacingControl
w:val="DontCompress"/><w:eek:ptimizeForBrowser/><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:p
wsp:rsidR="00D27B96" wsp:rsidRDefault="00D27B96"/><w:sectPr
wsp:rsidR="00D27B96"><w:pgSz w:w="12240" w:h="15840"/><w:pgMar 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:p><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:p></w:body></w:wordDocument>
 

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