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 / February 2005

Tip: Looking for answers? Try searching our database.

Protected documents

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chuck - 11 Feb 2005 19:13 GMT
Hi all

Is there any way to manipulate custom document properties and document
fields in non-protected sections of documents that contain protected sections?

I've got code that adds/changes custom doc properties and updates related
fields on open but any documents that have one or more sections protected
generate requests for the protection password -- cancelling past the password
request allows the macro to continue, but the properties/fields are not
added/deleted/changed.

Thanks for any thoughts...
Chuck
Doug Robbins - 12 Feb 2005 00:27 GMT
Show us the code.

Signature

Please respond to the Newsgroup for the benefit of others who may be
interested.   Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP

> Hi all
>
[quoted text clipped - 11 lines]
> Thanks for any thoughts...
> Chuck
Chuck - 14 Feb 2005 12:19 GMT
Hi Doug

Here's the AutoOpen macro.  I'm aware that I could hard code the document
protection password into the macro to unprotect it, change the document
property and then re-protect it, but I'd rather not do that because
protection passwords can vary.

Also I should mention that I've included code that checks the document view
and then at the end resets the view to the original view because looping
through the story ranges to update the document property fields changes the
view to Normal when it hits things like footers and footnotes.  I don't know
why but I had to use the Select Case code at the end to reset the view
because simply resetting the view to the numeric value (stored as nCurView)
didn't actually change the view.

In any case my real question is how do I change document properties in a
protected document without having to provide the password?  Thanks for any
help...

Chuck -- code follows:

Sub AutoOpen()

   On Error GoTo errorhandler

   Const DMS_DOC_REF_NAME As String = "DMSLink.(Default).Reference"
   
   Dim prpDocProp As DocumentProperty
   Dim bFound As Boolean
   Dim srStoryRange As Range
   Dim fldField As Field
   Dim s As String
   Static nCurView As Long
   
   bFound = False
   
   nCurView = CLng(ActiveDocument.ActiveWindow.View)
   
   For Each prpDocProp In ActiveDocument.CustomDocumentProperties
       With prpDocProp
           If .Name Like "DMSLink.*Reference" Then
               .Name = DMS_DOC_REF_NAME
               bFound = True
           End If
       Exit For
       End With
   Next prpDocProp
   
   If bFound = False Then
       ActiveDocument.CustomDocumentProperties.Add _
           Name:=DMS_DOC_REF_NAME, LinkToContent:=False,
Value:="[Reference]", _
           Type:=msoPropertyTypeString
   End If
   
   For Each srStoryRange In ActiveDocument.StoryRanges
       For Each fldField In srStoryRange.Fields
           If fldField.Type = wdFieldDocProperty Then
               With fldField
                   If .Code.Text Like "*DMSLink.*Reference*" Then
                       .Code.Text = " DOCPROPERTY """ & DMS_DOC_REF_NAME &
""" \* MERGEFORMAT "
                       .Update
                   End If
               End With
           End If
       Next fldField
   Next srStoryRange
   
   bFound = False
   
   Select Case nCurView
       Case 1
           ActiveDocument.ActiveWindow.View = wdNormalView
       Case 3
           ActiveDocument.ActiveWindow.View = wdPrintView
       Case 5
           ActiveDocument.ActiveWindow.View = wdOutlineView
       Case 6
           ActiveDocument.ActiveWindow.View = wdWebView
   End Select
   
   Exit Sub
   
errorhandler:

   MsgBox Err.Number & " " & Err.Description

End Sub

Rate this thread:






 
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.