Hi dave,
OK, I believe I understand your problem. Word documents are divided into
STORIES, or StoryRanges. For example, the headers and footers are separate
stories, so when you invoke ActiveDocument, they aren't affected. Same for
Drawing object, footnotes, etc.
The problem you're running into is that the margins aren't controlled within the
StoryRange. They're PageSetup settings, and are controlled through the SECTION.
When you replace the InnerXML, all you're affecting is the body text.
Essentially, I don't think it's possible to replace the current document with
another one by changing the XML property of the ActiveDocument. I believe you'd
have to serialize the document to disk, then open it.
*Possibly* you could get a similar looking document if you inserted a section
break at the very end of the XML document, containing the margin settings. This
section WOULD insert into the ActiveDocument, and retain those settings. Under
certain circumstances, however, the results could be... odd.
Thank you for responding. I have struck an issue. Say I save a word document
as XML and load this into SQL Server. This is the complete document with
margins set for each page. I created the test macro below (currently loading
from a file to simulate the stream actions). Margins in the save document are
set as top=0.5" bottom=1" left=1" right=1". After executing the macro below
(which is intended to replace the ActiveDocument with the XML document), the
margins have NOT been changed from the default blank document which is top=1"
bottom=1" left=1.25" right="1.25". So it looks like the document has been
inserted only and does not replace the current document. Am I going about
this the wrong way? Is there another solution?
Thanks, dave
Sub Macro10()
Dim strm As New ADODB.stream
strm.Open
strm.Type = adTypeText
strm.Charset = "UTF-8"
strm.LoadFromFile "testdoc.xml"
ActiveDocument.Range(0, ActiveDocument.Characters.Count).InsertXML
xml:=strm.ReadText
End Sub
Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org
This reply is posted in the Newsgroup; please post any follow question or reply
in the newsgroup and not by e-mail