A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

How to toggle Protect Form in macros



 
 
Thread Tools Display Modes
  #1  
Old March 24th, 2008, 05:34 PM posted to microsoft.public.word.tables
dickpaul
external usenet poster
 
Posts: 3
Default 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  
Old March 24th, 2008, 07:32 PM posted to microsoft.public.word.tables
Jay Freedman
external usenet poster
 
Posts: 9,488
Default 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  
Old March 25th, 2008, 01:25 AM posted to microsoft.public.word.tables
dickpaul
external usenet poster
 
Posts: 3
Default 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  
Old April 8th, 2008, 11:04 PM posted to microsoft.public.word.tables
dickpaul
external usenet poster
 
Posts: 3
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 10:10 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.