Avatar of DrTribos
Flag for Australia asked on

Edit Custom-XML in Office Documents WITHOUT Opening in MS Word


I have some MS Word Documents which contain Custom XML - the custom XML is easily seen by changing the file extension to zip then opening in Windows Explorer, (for example).  

I want to be able to quickly read and write to the custom XML without opening the document in MS Word.

Basically I'm looking for the CustomXML equivalent of DSOFile OLE Document Properties Reader (https://support.microsoft.com/en-us/kb/224351) which makes it possible to read and write custom and built-in document properties without opening the document in MS Word (or any other word processor).

I have found this MSDN article (https://msdn.microsoft.com/en-us/library/dd819387(v=office.12).aspx) which provides a possible (albeit clunky) way forward involving decompressing the Word Document, editing the XML and then recompressing... I was hoping for something more direct.  

I also attempted to use the OpenXMLSDK from MS but, this is for .Net and won't register in VBA :-(

Kind regards,
Microsoft OfficeMicrosoft WordMicrosoft ExcelXMLScripting Languages

Avatar of undefined
Last Comment
Rainer Jeschor

8/22/2022 - Mon

Use *.docx, then it's pretty simply: The newer Office formats are zipped XML files.

Thanks for your reply, I'm not sure exactly what you mean.  

The files are already docx, I understand that I can change the extension to ZIP and open, extract, edit, repack then (hopefully see my changes)... as per the MSDN article... is that what you are suggesting is a the best (perhaps only) approach?

I don't know, whether it is the best  or only approach. You have given to few information about your context and requirements.

But it is a simple approach. Could be done with lots of tools.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck

Hi ste5an

I'm not sure what more information I can give that would be helpful.  In MS Word it is possible to add Custom XML - this custom XML (when added via the VBA IDE using CustomXMLParts.Add always resides in the same 'folder' within the Word file.  All I want to do is read and write to it without opening the document in MS Word.

Within VBA this is done by (something like):
Set myXML = ThisDocument.CustomXMLParts.SelectByNamespace("http://www.me/mySchema")
readResult = myXML(1).SelectSingleNode _
          ("/ns0:SomeGroup[1]/ns0:Name[@SomeMember='" & MemberName & "']/ns0:" & SomeProperty & "[1]").Text

Open in new window

In a similar vein Microsoft provide tools to read and write Document Properties without opening the document in MS Word... so the concept is out there...
Rainer Jeschor

View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.