I am trying to created a form template (.dot) that has an invoice number that
automatically updates (+1) each time the template is used to created a new
document.

I found the following script for a macro that works great until I protect
the form. Then I get an error because the macro can't update a protected
area. I can't figure out how to "unprotect" the bookmark on the page so it
can update. Any ideas?

Sub AutoNew()

Order = System.PrivateProfileString("C:\Settings.Txt", _
"MacroSettings", "Order")

If Order = "" Then
Order = 1
Else
Order = Order + 1
End If

System.PrivateProfileString("C:\Settings.txt", "MacroSettings", _
"Order") = Order

ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Date, "yymmdd" &
"-") & Format(Order, "00#")
ActiveDocument.SaveAs FileName:="path" & Format(Order, "00#")

End Sub

Re: Numbered Documents - Protected Forms by Greg

Greg
Fri Feb 09 12:25:41 CST 2007

On Feb 9, 1:10 pm, Elisabeth <Elisab...@discussions.microsoft.com>
wrote:
> I am trying to created a form template (.dot) that has an invoice number that
> automatically updates (+1) each time the template is used to created a new
> document.
>
> I found the following script for a macro that works great until I protect
> the form. Then I get an error because the macro can't update a protected
> area. I can't figure out how to "unprotect" the bookmark on the page so it
> can update. Any ideas?
>
> Sub AutoNew()
>
> Order = System.PrivateProfileString("C:\Settings.Txt", _
> "MacroSettings", "Order")
>
> If Order = "" Then
> Order = 1
> Else
> Order = Order + 1
> End If
>
> System.PrivateProfileString("C:\Settings.txt", "MacroSettings", _
> "Order") = Order
>
> ActiveDocument.Bookmarks("Order").Range.InsertBefore Format(Date, "yymmdd" &
> "-") & Format(Order, "00#")
> ActiveDocument.SaveAs FileName:="path" & Format(Order, "00#")
>
> End Sub

Try:

If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect
End If
'Your code
ActiveDocument.Protect wdAllowOnlyFormFields, NoReset:=True