J
Jason Lepack
I have a document on which the requirement is to force users to enter
data in specific fields in the top half of the first page and the
header. The rest of the document must be freely editable.
I created form fields in the page and then bookmarks in the header. I
split the page into two sections and set allow only form entries in
the first section.
Now I can't modify the header because it's protected (which is what I
want, because I don't want users accidentally deleting the bookmarks,
things are too fragile...) so I created a command button to modify the
header code is below:
Private Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As
String)
On Error GoTo updBM_Err
Dim BMRange As Range, doc As Document
Set doc = ActiveDocument
doc.Unprotect "toughpassword"
Set BMRange = doc.Bookmarks(BookmarkToUpdate).Range
BMRange.Text = TextToUse
doc.Bookmarks.Add BookmarkToUpdate, BMRange
doc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:="toughpassword"
Exit Sub
updBM_Err:
If Err.Number = 4605 Then
Resume Next
Else
MsgBox Err.Number & " - " & Err.Description
End If
End Sub
' Prompts the user to modify the header
' Called by command button
Public Sub modifyHeader()
Dim s As String
s = InputBox("Enter a Title for your Document", , " ")
If Not s = "" Then UpdateBookmark "Title", s
s = InputBox("Enter a Document Number", , " ")
If Not s = "" Then UpdateBookmark "DocNum", s
s = InputBox("Enter a Revision Number", , " ")
If Not s = "" Then UpdateBookmark "RevNum", s
End Sub
That worked great but the command button showed up on print.
So I found the method of inserting the button into a text box and
hiding the text box on print. That worked great too.
Now here's the current problem. When I click my button I get the
error at doc.protect:
Err.Number = 4641
Err.Description = The ToolsProtectDocument statement is currently
disabled
So with just the button, runs fine, button prints.
Button in text box, button doesn't print, document won't reprotect.
ANy help on this situation, including other methods, would be greatly
appreciated. I've created lots of Excel and Access solutions, but
this is my first Word Macro.
Thanks,
Jason Lepack
data in specific fields in the top half of the first page and the
header. The rest of the document must be freely editable.
I created form fields in the page and then bookmarks in the header. I
split the page into two sections and set allow only form entries in
the first section.
Now I can't modify the header because it's protected (which is what I
want, because I don't want users accidentally deleting the bookmarks,
things are too fragile...) so I created a command button to modify the
header code is below:
Private Sub UpdateBookmark(BookmarkToUpdate As String, TextToUse As
String)
On Error GoTo updBM_Err
Dim BMRange As Range, doc As Document
Set doc = ActiveDocument
doc.Unprotect "toughpassword"
Set BMRange = doc.Bookmarks(BookmarkToUpdate).Range
BMRange.Text = TextToUse
doc.Bookmarks.Add BookmarkToUpdate, BMRange
doc.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:="toughpassword"
Exit Sub
updBM_Err:
If Err.Number = 4605 Then
Resume Next
Else
MsgBox Err.Number & " - " & Err.Description
End If
End Sub
' Prompts the user to modify the header
' Called by command button
Public Sub modifyHeader()
Dim s As String
s = InputBox("Enter a Title for your Document", , " ")
If Not s = "" Then UpdateBookmark "Title", s
s = InputBox("Enter a Document Number", , " ")
If Not s = "" Then UpdateBookmark "DocNum", s
s = InputBox("Enter a Revision Number", , " ")
If Not s = "" Then UpdateBookmark "RevNum", s
End Sub
That worked great but the command button showed up on print.
So I found the method of inserting the button into a text box and
hiding the text box on print. That worked great too.
Now here's the current problem. When I click my button I get the
error at doc.protect:
Err.Number = 4641
Err.Description = The ToolsProtectDocument statement is currently
disabled
So with just the button, runs fine, button prints.
Button in text box, button doesn't print, document won't reprotect.
ANy help on this situation, including other methods, would be greatly
appreciated. I've created lots of Excel and Access solutions, but
this is my first Word Macro.
Thanks,
Jason Lepack