If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
How to toggle Protect Form in macros
I have a macro to add a line to a table on a template. It works when I click
Protect Form button and click Protect Form again after the macro completes. I want to toggle the button in the macro so I don't have to do it manually. |
#2
|
|||
|
|||
How to toggle Protect Form in macros
dickpaul wrote:
I have a macro to add a line to a table on a template. It works when I click Protect Form button and click Protect Form again after the macro completes. I want to toggle the button in the macro so I don't have to do it manually. Depending on whether you've added a password to the form protection, use one of these arrangements: Sub Whatever() ' unprotect If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ' do whatever you need here ' reprotect without emptying the fields ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _ NoReset:=True End Sub Sub WhateverWithPassword() Const myPassword = "asdf1234" ' unprotect If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect Password:=myPassword End If ' do whatever you need here ' reprotect without emptying the fields ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _ NoReset:=True, Password:=myPassword End Sub -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. |
#3
|
|||
|
|||
How to toggle Protect Form in macros
This looks exactly what I needed. Thank you Jay.
"Jay Freedman" wrote: dickpaul wrote: I have a macro to add a line to a table on a template. It works when I click Protect Form button and click Protect Form again after the macro completes. I want to toggle the button in the macro so I don't have to do it manually. Depending on whether you've added a password to the form protection, use one of these arrangements: Sub Whatever() ' unprotect If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ' do whatever you need here ' reprotect without emptying the fields ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _ NoReset:=True End Sub Sub WhateverWithPassword() Const myPassword = "asdf1234" ' unprotect If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect Password:=myPassword End If ' do whatever you need here ' reprotect without emptying the fields ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _ NoReset:=True, Password:=myPassword End Sub -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. |
#4
|
|||
|
|||
How to toggle Protect Form in macros
Excellent job
"dickpaul" wrote: This looks exactly what I needed. Thank you Jay. "Jay Freedman" wrote: dickpaul wrote: I have a macro to add a line to a table on a template. It works when I click Protect Form button and click Protect Form again after the macro completes. I want to toggle the button in the macro so I don't have to do it manually. Depending on whether you've added a password to the form protection, use one of these arrangements: Sub Whatever() ' unprotect If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect End If ' do whatever you need here ' reprotect without emptying the fields ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _ NoReset:=True End Sub Sub WhateverWithPassword() Const myPassword = "asdf1234" ' unprotect If ActiveDocument.ProtectionType wdNoProtection Then ActiveDocument.Unprotect Password:=myPassword End If ' do whatever you need here ' reprotect without emptying the fields ActiveDocument.Protect Type:=wdAllowOnlyFormFields, _ NoReset:=True, Password:=myPassword End Sub -- Regards, Jay Freedman Microsoft Word MVP FAQ: http://word.mvps.org Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit. |
Thread Tools | |
Display Modes | |
|
|