Page 1 of 3 123 LastLast
Results 1 to 15 of 34
  1. #1
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking

    Using Word2007 I would like to use a single command button that would do both add protection and unprotect like a toggle type method, press it once protection is added, press it again unprotected.
    I know how to add protection
    Code:
    ActiveDocument.Protect wdAllowOnlyFormFields, NoReset:=True, Password:=""
    and I know how to unprotect
    Code:
    ActiveDocument.Unprotect ""
    I'm just not sure how to put them together to use in the method as i mentioned

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Try this:

    Code:
    If ActiveDocument.ProtectionType = wdNoProtection Then
      ActiveDocument.Protect wdAllowOnlyFormFields, True
    Else
      ActiveDocument.Unprotect
    End If

  3. #3
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='791365' date='30-Aug-2009 08:03']Try this:

    Code:
    If ActiveDocument.ProtectionType = wdNoProtection Then
      ActiveDocument.Protect wdAllowOnlyFormFields, True
    Else
      ActiveDocument.Unprotect
    End If
    [/quote]
    Thank You HansV

  4. #4
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi HansV
    I adjusted these code to use a password, since the word.docm is password protected already and it works great. the command button toggles perfect.
    Code:
    If ActiveDocument.ProtectionType = wdNoProtection Then
    	ActiveDocument.Protect wdAllowOnlyFormFields, True, Password:="Password here"
    Else
      ActiveDocument.Unprotect "Password here"
    Now lets say the document is protected and I want to enter a photo, naturally it will not let me until I unprotect the document.
    I tried a couple differents ways with no success. I removed the no on protection thinking that might be it or maybe its my location, not sure.

    Code:
    Dim sFileName As String
    	Dim ilImage As InlineShape
    
      If ActiveDocument.ProtectionType = wdProtection Then
    ActiveDocument.Unprotect "Password here"
     
    	 With Dialogs(wdDialogInsertPicture)
    		.Display
    		If .Name <> "" Then
    			sFileName = .Name
    Set ilImage = Selection.InlineShapes.AddPicture(sFileName, , True)
    
    			With ilImage
    				'set any additional properties such as left, top, etc., here
    			End With
    		Else
    			Exit Sub
    		End If
    	End With
    End Sub

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    1. Unlike wdNoProtection, wdProtection is not a valid constant. You must provide a specific protection type such as wdAllowOnlyFormFields.
    2. You should not exit the macro if the user cancels the dialog - it would leave the document unprotected.

    Here is a working version:

    Code:
    Sub InsertImageInProtectedDocument()
      Dim sFileName As String
      Dim ilImage As InlineShape
    
      If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
    	ActiveDocument.Unprotect "Password here"
      End If
      With Dialogs(wdDialogInsertPicture)
    	.Display
    	If .Name <> "" Then
    	  sFileName = .Name
    	  Set ilImage = Selection.InlineShapes.AddPicture(sFileName, , True)
    	  With ilImage
    		'set any additional properties such as left, top, etc., here
    	  End With
    	End If
      End With
      ActiveDocument.Protect wdAllowOnlyFormFields, True, "Password here"
    End Sub

  6. #6
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='791398' date='30-Aug-2009 15:19']1. Unlike wdNoProtection, wdProtection is not a valid constant. You must provide a specific protection type such as wdAllowOnlyFormFields.
    2. You should not exit the macro if the user cancels the dialog - it would leave the document unprotected.

    Here is a working version:

    Code:
    Sub InsertImageInProtectedDocument()
      Dim sFileName As String
      Dim ilImage As InlineShape
    
      If ActiveDocument.ProtectionType = wdAllowOnlyFormFields Then
    	ActiveDocument.Unprotect "Password here"
      End If
      With Dialogs(wdDialogInsertPicture)
    	.Display
    	If .Name <> "" Then
    	  sFileName = .Name
    	  Set ilImage = Selection.InlineShapes.AddPicture(sFileName, , True)
    	  With ilImage
    		'set any additional properties such as left, top, etc., here
    	  End With
    	End If
      End With
      ActiveDocument.Protect wdAllowOnlyFormFields, True, "Password here"
    End Sub
    [/quote]

    Hi HansV
    I would like to add on this if I may. This code you have provided works great, except for one thing. In order to insert a photo in a desired table / location the cursor needs to be there prior to running the code. The problem I have is, while protection is applied I am unable to move the cursor around as needed.

    I thought of using “Picture Content Controls”, because they do not seem to be affected with protection on or off, I able to insert them everywhere, the only problem I have with “Picture Content Controls” are, If one is not used it is visible as a grey box when printing. Is there a way to eliminate this grayish highlighting when printing?

    What my goal is, to be able to leave the protection on and still be able to use needed controls.

    What might be your thoughts?

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    I don't know what "picture content controls" are - I don't have Word 2007.

    You can leave specific sections in the document unprotected; users can insert pictures there without using code.

  8. #8
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi HansV
    You can leave specific sections in the document unprotected; users can insert pictures there without using code.
    I like this it sound very interesting, I use tables throughout my document, so how do I unprotect a certain table, while still having the rest of document protected

  9. #9
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Activate the Developer tab of the ribbon.
    In the Protect group, click "Protect document".
    Click "Restrict formatting and editing" to display the protection task pane.
    Tick the check box "Allow only this type of editing in the document" under "Editing restrictions".
    Select "Filling in forms" from the dropdown list.
    Click "Select sections..."
    You'll see a list of all the sections in the document, with check boxes.
    Clear the check box for sections that you want to leave unprotected.
    Click OK.
    Click "Yes, start enforcing protection".
    Attached Images Attached Images
    • File Type: jpg x.jpg (29.3 KB, 0 views)

  10. #10
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='HansV' post='795302' date='28-Sep-2009 08:22']Activate the Developer tab of the ribbon.
    In the Protect group, click "Protect document".
    Click "Restrict formatting and editing" to display the protection task pane.
    Tick the check box "Allow only this type of editing in the document" under "Editing restrictions".
    Select "Filling in forms" from the dropdown list.
    Click "Select sections..."
    You'll see a list of all the sections in the document, with check boxes.
    Clear the check box for sections that you want to leave unprotected.
    Click OK.
    Click "Yes, start enforcing protection".[/quote]
    Hi HansV
    of course with Office 2007 I cant seem to find "Select sections" right below "Filling in forms" from the dropdown list. I looked around and was uable to locate?

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    What happens if you click Protect Document in the Protect group of the Review tab of the ribbon instead of the Developer tab?

  12. #12
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi HansV
    Same options no changes

  13. #13
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts
    [quote name='ababenchrist' post='795308' date='28-Sep-2009 16:47']Hi HansV
    of course with Office 2007 I cant seem to find "Select sections" right below "Filling in forms" from the dropdown list. I looked around and was uable to locate?[/quote]

    Have a look here...
    [attachment=85721:SelectSections.png]
    Attached Images Attached Images

  14. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Sorry, can't help you then. I hope that someone who has Word 2007 knows where Microsoft has hidden this option.

  15. #15
    3 Star Lounger
    Join Date
    Jun 2009
    Location
    Hemet CA
    Posts
    310
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank You HansV
    I really like the idea of unprotecting selected tables. I'll do more searching and see what I can find
    Here is a view of my window
    [attachment=85725:4.png]
    Attached Images Attached Images
    • File Type: png 4.png (36.8 KB, 1 views)

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •