Saving Document Properties in Code

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

I am trying to write code to save document properties
through my own dialog in VB7. My Code looks something
like:

Dim oDoc As Word.Document
oDoc = oApp.Documents.Open(FileName:=strFile,
ReadOnly:=False)
oDoc.BuiltInDocumentProperties("Title").Value = "MyText"
oDoc.Save()
oDoc.Close
(SaveChanges:=Word.WdSaveOptions.wdPromptToSaveChanges)

This works on a new document, but after the first time I
save the properties, I can never save them to something
else.
Any Ideas ?
 
Hi Paul,

"code looks something like" isn't good enough, in this
case. What is the exact NET code you're using? Also, which
version of Word is involved?

Do you see anything different if you leave one of the Save
parts out? And are you getting any error messages?

If you open such a document manually in Word are you able
to make and save changes to the properties?
I am trying to write code to save document properties
through my own dialog in VB7. My Code looks something
like:

Dim oDoc As Word.Document
oDoc = oApp.Documents.Open(FileName:=strFile,
ReadOnly:=False)
oDoc.BuiltInDocumentProperties("Title").Value = "MyText"
oDoc.Save()
oDoc.Close
(SaveChanges:=Word.WdSaveOptions.wdPromptToSaveChanges)

This works on a new document, but after the first time I
save the properties, I can never save them to something
else.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Sep 30 2003)
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
:-)
 
OK THis is my exact code

1. If the DocNumber field does not exist - it fails to
create it
2. If it does exist it fails to update it.

Any ideas
TIA

Private Sub btnTest_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btnTest.Click
Dim strFile As String
' txtDocNumber is an edit field
' public variables
' Dim oApp As Word.Application
' Dim oDoc As Word.Document
On Error Resume Next

' in form load
' oApp = New Word.Application

strFile = txtDocument.Text
oDoc = oApp.Documents.Open(FileName:=strFile)

With oDoc.CustomDocumentProperties
.item("DocNumber").Value = txtDocNumber.Text
If Err.Number = 5 Then
Err.Clear()
.Add(Name:="DocNumber", _
LinkToContent:=False, _

Type:=Office.MsoDocProperties.msoPropertyTypeString, _
Value:=txtDocNumber.Text)
If Err.Number <> 0 Then
MsgBox(Err.Description)
End If
Err.Clear()
End If
txtDocNumber.Text = .item("DocNumber").Value
End With

oDoc.Close
(SaveChanges:=Word.WdSaveOptions.wdPromptToSaveChanges)
If Err.Number <> 0 Then
MsgBox(Err.Description)
End If
oDoc = Nothing


End Sub
 
Back
Top