Numbered Documents - Protected Forms

E

Elisabeth

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
 
G

Greg Maxey

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top