Discussion:
CustomDocumentProperty not working correctly
(too old to reply)
Dhananjay
2009-05-28 13:43:40 UTC
Permalink
Hi All,
I am developing word Addin using VB 2005 / VSTO / Office 2007.
I want to write some CustomDocumentProperties to the document. So I
used the code snippet below
-----------------------------------------------------------

doc = Application.ActiveDocument
Dim myProperties(,) As String = {{"ID", "ID1"}, {"NAME",
"Name1"}}
prps = doc.CustomDocumentProperties
For i As Int16 = 0 To myProperties.GetUpperBound(0)
prps.Add(myProperties(i, 0), False,
Microsoft.Office.Core.MsoDocProperties.msoPropertyTypeString,
myProperties(i, 1))
Next
doc.Save ' Save as File.Docx
' Copy File from doc.FullName to some other folder
dim myFolder = "c:\temp\"
File.Copy doc.FullName,myFolder

' Open document from myFolder
dim myTempDoc as Document = Application.Documents.Open
(myFolder & "File.docx")
myTempDoc.CustomDocumentProperties("Name").value= "Name
changed"
myTempDoc.Save
myTempDoc.Close

-----------------------------------------------------------
But when I open myTempDoc again, it shows me value for Name & ID as
"Name1" & "ID1"

Please help me to resolve this problem.

Thanks in advance,
Dhananjay
Cindy M.
2009-05-29 08:19:14 UTC
Permalink
Hi Dhananjay,

Word has a little "thing" where it only saves the document when it
thinks the document is dirty. In my experience, just changing the
value of a doc property doesn't trigger the "dirty" flag, so Word
simply doesn't save.

To test, try using SaveAs to a new file name or location.

If you don't want to do this in your final scenario, you need to
change something in the document, then change it back (DON'T use
Undo!). Enter a character at the beginning, then delete it, for
example.
Post by Dhananjay
I am developing word Addin using VB 2005 / VSTO / Office 2007.
I want to write some CustomDocumentProperties to the document. So I
used the code snippet below
-----------------------------------------------------------
doc = Application.ActiveDocument
Dim myProperties(,) As String = {{"ID", "ID1"}, {"NAME",
"Name1"}}
prps = doc.CustomDocumentProperties
For i As Int16 = 0 To myProperties.GetUpperBound(0)
prps.Add(myProperties(i, 0), False,
Microsoft.Office.Core.MsoDocProperties.msoPropertyTypeString,
myProperties(i, 1))
Next
doc.Save ' Save as File.Docx
' Copy File from doc.FullName to some other folder
dim myFolder = "c:\temp\"
File.Copy doc.FullName,myFolder
' Open document from myFolder
dim myTempDoc as Document = Application.Documents.Open
(myFolder & "File.docx")
myTempDoc.CustomDocumentProperties("Name").value= "Name
changed"
myTempDoc.Save
myTempDoc.Close
-----------------------------------------------------------
But when I open myTempDoc again, it shows me value for Name & ID as
"Name1" & "ID1"
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 :-)
Jean-Guy Marcil
2009-05-29 14:26:33 UTC
Permalink
Post by Cindy M.
Hi Dhananjay,
Word has a little "thing" where it only saves the document when it
thinks the document is dirty. In my experience, just changing the
value of a doc property doesn't trigger the "dirty" flag, so Word
simply doesn't save.
To test, try using SaveAs to a new file name or location.
If you don't want to do this in your final scenario, you need to
change something in the document, then change it back (DON'T use
Undo!). Enter a character at the beginning, then delete it, for
example.
How about just setting the Document.Saved flag to False?
--
______________________________
Jean-Guy Marcil
Montreal, Canada
Cindy M.
2009-05-29 15:51:26 UTC
Permalink
Hi Jean-Guy,
Post by Jean-Guy Marcil
How about just setting the Document.Saved flag to False?
You could try that, but I'm not sure whether it would work,
which is why I didn't suggest it (and I haven't time to
test).

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
:-)
Jean-Guy Marcil
2009-05-29 21:08:31 UTC
Permalink
Post by Cindy M.
Hi Jean-Guy,
Post by Jean-Guy Marcil
How about just setting the Document.Saved flag to False?
You could try that, but I'm not sure whether it would work,
which is why I didn't suggest it (and I haven't time to
test).
OK, I just tried and it does work (Word 2003 SP3).
--
______________________________
Jean-Guy Marcil
Montreal, Canada
Loading...