Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-17-2020, 11:26 AM
GDixit GDixit is offline VBA, Allow only Form Fields to edit in MSword Windows 10 VBA, Allow only Form Fields to edit in MSword Office 2010
Novice
VBA, Allow only Form Fields to edit in MSword
 
Join Date: Aug 2020
Posts: 2
GDixit is on a distinguished road
Default VBA, Allow only Form Fields to edit in MSword

I am trying to write a macro, which should restrict any changes to Form except allowing content control properties.

I tried this macro, it does work and allows modification only to form fields(content control properties), however takes away capabilities to insert any image or table in these content control properties.

Sub Protect_FormFields()


'
' Protect_FormFields Macro
'
'
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True
End If

End Sub


I need the option to add a table. If I manually select all form fields -> restrict editing -> select 'allow only this type of editing in the document' -> under exception select 'everyone' -> yes, start enforcing protection => then it works as expected ( allows only form fields editing & still can add table/image to form fields).

I am struggling to write a generic loop which should select all content control properties & then explicitly allow only selection for modification in a document

Selection.Editors.Add wdEditorEveryone

and apply below code on the rest of document.

ActiveDocument.Protect Password:="", NoReset:=False, Type:= _
wdAllowOnlyReading, UseIRM:=False, EnforceStyleLock:=False


I will really appreciate help/pointers to proceed
Reply With Quote
  #2  
Old 08-17-2020, 01:59 PM
gmaxey gmaxey is offline VBA, Allow only Form Fields to edit in MSword Windows 10 VBA, Allow only Form Fields to edit in MSword Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,427
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Form Fields and Content Controls are not the same thing.



First you say your want to protect everything in a form except content control properties. Tables and images "aren't" properties of a CC. They are content. I think you need to use "No Changes - Read Only" and apply the editor "Everyone the the CCs you want user's to be able to type in or add images.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 08-17-2020, 06:39 PM
macropod's Avatar
macropod macropod is offline VBA, Allow only Form Fields to edit in MSword Windows 7 64bit VBA, Allow only Form Fields to edit in MSword Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Cross-posted at: ms word - VBA, Allow only Form Fields to edit in MSword - Stack Overflow
For cross-posting etiquette, please read: Excelguru Help Site - A message to forum cross posters
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 08-20-2020, 11:33 AM
GDixit GDixit is offline VBA, Allow only Form Fields to edit in MSword Windows 10 VBA, Allow only Form Fields to edit in MSword Office 2010
Novice
VBA, Allow only Form Fields to edit in MSword
 
Join Date: Aug 2020
Posts: 2
GDixit is on a distinguished road
Default I could develop macro for my requirements

Sub Protect_Form_Fields_2()
'
' Protect_Form_Fields_2 Macro
'
'
Dim i As Long
Dim startPos As Integer
Dim endPos As Integer

With ActiveDocument
For i = 1 To .ContentControls.Count
Set ContentControl = .ContentControls(i)
startPos = ContentControl.Range.Start - 1
endPos = ContentControl.Range.End + 1
Application.ActiveDocument.Range(startPos, endPos).Editors.Add WdEditorType.wdEditorEveryone

Next i
.Protect Password:="NoChange", NoReset:=False, Type:= _
wdAllowOnlyReading, UseIRM:=False, EnforceStyleLock:=False
End With
End Sub
Reply With Quote
Reply

Tags
msword, vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA, Allow only Form Fields to edit in MSword Don't clear form fields when protecting as a form BruceM Word 5 10-06-2016 08:26 AM
Macro to keep formatted form fields after mail merge or replace text with formatted form fields jer85 Word VBA 2 04-05-2015 10:00 PM
Using MSWord 2003 docs in MSWord 2010 Joe Watson Word 7 05-31-2014 11:27 AM
VBA, Allow only Form Fields to edit in MSword MSWord forms use list to populate successive text fields 2surgeons Word 4 03-05-2012 07:19 PM
VBA, Allow only Form Fields to edit in MSword Form Fields - Create blank form text field with if statement? LAssist2011 Word 5 12-14-2011 03:02 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:40 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft