Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2005

Tip: Looking for answers? Try searching our database.

Saving document after adding custom property?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Derrick - 19 Jul 2005 07:14 GMT
Hi All
This is my first dip into VBA, so apologies if the question is trivial.
I am wanting to add the same set of custom properties to a large number of
documents, and hoped the following code (synthesized from various examples)
would work.
The problem is that the SAVE statement does not have any effect, although
the CLOSE statement does.
If I interrupt execution before the CLOSE, I see that the custom property
has been added successfully. The debugging display before the SAVE shows a
value of TRUE for ActiveDocument.Saved.
What should I do to SAVE the document?
Thanks & regards
Derrick

(Code follows:
Public Sub AddProperty()
' Display FileOpen dialogue box to select file
If Dialogs(wdDialogFileOpen).Show = -1 Then
' OK button selected, process file
   With ActiveDocument.CustomDocumentProperties
       .Add Name:="MyNewProperty", _
           LinkToContent:=False, _
           Type:=msoPropertyTypeString, _
           Value:="My new value"
    ' Debugging: following line displays a value of "True"
           MsgBox (ActiveDocument.Saved)
       ActiveDocument.Save
       ActiveDocument.Close
   'Also tried following option to save document
       'ActiveDocument.Close SaveChanges:=wdSaveChanges
   End With
End If
End Sub
Doug Robbins - 19 Jul 2005 12:25 GMT
Try moving them both outside of the With - End With construction.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Hi All
> This is my first dip into VBA, so apologies if the question is trivial.
[quoted text clipped - 30 lines]
> End If
> End Sub
Derrick - 19 Jul 2005 14:07 GMT
Hi
I tried this but it does not seem to make any difference. The document is
still not being saved.
Thanks for the suggestion, though. It does make the code more logical.
Forgot to mention I'm using Word 2000, SP3.
Rgds
Derrick

> Try moving them both outside of the With - End With construction.
Derrick - 19 Jul 2005 15:09 GMT
Hi
I don't pretend to understand this, but after inserting a "MsgBox" display
of the "Keywords" built-in property just before the WITH construct (for a
completely different reason), the SAVE now works, and the debugging display
before the SAVE now shows a value of TRUE for ActiveDocument.Saved.
The current (working) code is as follows:

Public Sub AddProperty()
Dim DocId As String
' Display FileOpen dialogue box to select file
If Dialogs(wdDialogFileOpen).Show = -1 Then
' OK button selected, process file
' ========== ADDED THESE LINES ================
   DocId = ActiveDocument.BuiltInDocumentProperties(wdPropertyKeywords)
   MsgBox (DocId)
' ========================================
   With ActiveDocument.CustomDocumentProperties
       .Add name:="MyNewProperty", _
           LinkToContent:=False, _
           Type:=msoPropertyTypeString, _
           Value:="My new value"
    ' Debugging: following line displays a value of "True"
           MsgBox (ActiveDocument.Saved)
       'ActiveDocument.Save
       'ActiveDocument.Close
   'Also tried following option to save document
       'ActiveDocument.Close SaveChanges:=wdSaveChanges
   End With
   MsgBox (ActiveDocument.name)
   ActiveDocument.Save
   ActiveDocument.Close
End If
End Sub

Regards
Derrick
Chuck Henrich - 19 Jul 2005 16:35 GMT
Hi Derrick

An alternative fix is to add Activedocument.Saved=False before saving (as
per the amended code below).  Seems like adding a custom document property
doesn't "dirty" a document enough to trigger Saved=False.  
HTH
Chuck

Public Sub AddProperty()
' Display FileOpen dialogue box to select file
If Dialogs(wdDialogFileOpen).Show = -1 Then
' OK button selected, process file
   With ActiveDocument.CustomDocumentProperties
       .Add Name:="MyNewProperty", _
           LinkToContent:=False, _
           Type:=msoPropertyTypeString, _
           Value:="My new value"
'NEW LINE --------------------------------------
       ActiveDocument.Saved = False
'-----------------------------------------------
       MsgBox (ActiveDocument.Saved)
       ActiveDocument.Save
       ActiveDocument.Close
   'Also tried following option to save document
       'ActiveDocument.Close SaveChanges:=wdSaveChanges
   End With
End If
End Sub

> Hi
> I don't pretend to understand this, but after inserting a "MsgBox" display
[quoted text clipped - 32 lines]
> Regards
> Derrick
Derrick Ackermann - 31 Aug 2005 13:09 GMT
Hi Chuck
Sorry for the belated "thank you". This seems the perfect workaround.
Regards

> Hi Derrick
>
[quoted text clipped - 61 lines]
> > Regards
> > Derrick
Chuck Henrich - 31 Aug 2005 13:14 GMT
You're welcome, glad to help.
Signature

Chuck Henrich
www.ProductivityApps.com

> Hi Derrick
>
[quoted text clipped - 61 lines]
> > Regards
> > Derrick
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.