Inserting WordML when a document is open

B

Big Dave

Can this be done?

At the moment - to build a document from building blocks - I am looking at
using the Word object model (potentially slow) or closing the document and
inserting WordML into the structure (potentially very complex and risky).

Is anyone aware of another way?

Thanks!
 
B

Big Dave

I just tried the following in a Word 2007 document. Cursor was just sat at a
'normal' paragraph: -

Selection.Range.InsertXML "<w:sdt><w:sdtPr><w:alias
w:val=""BigDaveCCTitle""/><w:tag w:val=""BigDaveCCTag""/><w:id
w:val=""787055938""/><w:lock w:val=""sdtLocked""/><w:placeholder><w:docPart
w:val=""230BB5C784404BD4851EE8BA581A73CE""/></w:placeholder><w:showingPlcHdr/></w:sdtPr><w:sdtContent><w:p
w:rsidR=""00B84263"" w:rsidRDefault=""00B84263""><w:r><w:rPr><w:rStyle
w:val=""PlaceholderText""/></w:rPr><w:t>BigDaveCCContent</w:t></w:r></w:p></w:sdtContent></w:sdt>"

The WordML is a content type recorded in a Building Block. This is the sort
of thing I would need to do.

The above got the error message: -

Run-time error '6145': XML Markup cannot be insert in the specific location.

What am I doing wrong?
 
C

Cindy M.

Hi Dave,

You'll get faster responses in a word.vba or office.developer newsgroup than this
one, targeted at end-users...

In order to insert XML into a Word document you need to wrap the XML properly. It
has to be valid WordML, which means you also need the file headers. Create a
document with just what you're trying to insert, then save it as XML. Take a look at
what it generates. You don't need all of that (defitions of styles, lists of fonts,
etc) But you do need the first three elements (xml, application id and the
w:document element with any namespace prefixes you use in the XML you're passing
using InsertXML).
I just tried the following in a Word 2007 document. Cursor was just sat at a
'normal' paragraph: -

Selection.Range.InsertXML "<w:sdt><w:sdtPr><w:alias
w:val=""BigDaveCCTitle""/><w:tag w:val=""BigDaveCCTag""/><w:id
w:val=""787055938""/><w:lock w:val=""sdtLocked""/><w:placeholder><w:docPart
w:val=""230BB5C784404BD4851EE8BA581A73CE""/> said:
w:rsidR=""00B84263"" w:rsidRDefault=""00B84263""><w:r><w:rPr><w:rStyle
w:val=""PlaceholderText""/> said:
The WordML is a content type recorded in a Building Block. This is the sort
of thing I would need to do.

The above got the error message: -

Run-time error '6145': XML Markup cannot be insert in the specific location.

What am I doing wrong?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
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 :)
 

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