Word fails to save custom document properties

Article translations Article translations
Article ID: 195425 - View products that this article applies to.
This article was previously published under Q195425
Expand all | Collapse all


Custom document properties that are added to a Microsoft Word document by using Automation are not saved after the code calls "Save."


Word does not "dirty" the document when custom document properties are added by usingAutomation. When the document is not dirty, calls to "Save" just return without performing anything.


In the document to which you are adding properties, set the "Saved" property to False. This will let Word know the document must be saved.


This behavior is by design.


The following Visual Basic code demonstrates how to add a custom document property and set the "Saved" property to False:
' Launch Word
   Dim wdapp As Object
   Set wdapp = CreateObject("Word.Application")

   ' Make it visible...
   wdapp.Visible = True

   ' Open a document...
   Dim doc As Object<?xm-insertion_mark_start author="v-thomr" time="20070416T123039-0600"?>
<?xm-insertion_mark_end?>   ' In Word 2007, change the document name to testdoc.docx.
   Set doc = wdapp.Documents.Open("C:\mydocu~1\testdoc.doc")

   ' Add a custom document property...
   doc.CustomDocumentProperties.Add "MyProp", False, 1, 123

   ' Uncomment this line to let Word know document is "dirty," so it
   ' will save the new Custom Document Property.
   'doc.Saved = False

   ' Save document

   ' Close Word...


Article ID: 195425 - Last Review: April 16, 2007 - Revision: 5.1
  • Microsoft Visual Basic 5.0 Learning Edition
  • Microsoft Visual Basic 6.0 Learning Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic Enterprise Edition for Windows 6.0
  • Microsoft Office XP Developer Edition
  • Microsoft Office 2000 Developer Edition
  • Microsoft Office Word 2007
  • Microsoft Office Word 2003
  • Microsoft Word 2002
  • Microsoft Word 2000
  • Microsoft Word 97 Standard Edition
kbexpertiseinter kbautomation kbprb KB195425

Give Feedback


Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com