![]() |
|
#1
|
|||
|
|||
|
Hi all,
I have a document populated with Content Controls in a table. I created a macro to add a row at the bottom of the table and populate the fields with additional content controls. Before adding the row the macro unprotects the document... ActiveDocument.UnprotectThis works perfectly. The last line of the macro is supposed to protect the document again... ActiveDocument.Protect wdAllowOnlyFormFields, TrueHowever, it doesn't work. I tried this format as well because I saw it in some other code... ActiveDocument.Protect Type:=wdAllowOnlyFormFields, noreset:=TrueBut it still doesn't work. Any suggestions on what I might be doing wrong? ![]() EDIT: Here is the full code (please excuse the woefully inefficient coding, I am still a newbie in VBA)... Code:
Sub AddTableRow()
'
' AddTableRow Macro
'
'
Dim tRows As Integer
Dim objCC As ContentControl
Call UnProtectForm
Selection.Tables(1).Rows.Add
Selection.EndKey Unit:=wdColumn
'Selection.Cells(1).Next.Select
Selection.StartOf Unit:=wdRow
tRows = Selection.Information(wdMaximumNumberOfRows)
tRows = tRows - 8
Selection.TypeText tRows
Selection.Cells(1).Next.Select
Set objCC = ActiveDocument.ContentControls.Add(wdContentControlRichText)
objCC.SetPlaceholderText Text:=" "
objCC.Appearance = wdContentControlHidden
Selection.Cells(1).Next.Select
Set objCC = ActiveDocument.ContentControls.Add(wdContentControlPlainText)
objCC.SetPlaceholderText Text:=" "
objCC.Appearance = wdContentControlHidden
Selection.Cells(1).Next.Select
Set objCC = ActiveDocument.ContentControls.Add(wdContentControlPlainText)
objCC.SetPlaceholderText Text:=" "
objCC.Appearance = wdContentControlHidden
Selection.Cells(1).Next.Select
Set objCC = ActiveDocument.ContentControls.Add(wdContentControlPlainText)
objCC.SetPlaceholderText Text:=" "
objCC.Appearance = wdContentControlHidden
Selection.Cells(1).Next.Select
Set objCC = ActiveDocument.ContentControls.Add(wdContentControlPlainText)
objCC.SetPlaceholderText Text:="PASS"
objCC.Appearance = wdContentControlHidden
Selection.StartOf Unit:=wdRow
ThisDocument.NextCell
Call ProtectForm
End Sub
Sub UnProtectForm()
If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect
End If
End Sub
Sub ProtectForm()
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If
End Sub
|
| Tags |
| protect, unprotect, vba |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Spell out a number without protecting a document
|
vera | Word VBA | 2 | 05-20-2016 07:35 AM |
| Protecting document | brucemc777 | Word | 2 | 01-23-2016 02:38 PM |
Cant type into content controls in a form after protecting document using macro
|
rgburridge | Word VBA | 4 | 01-27-2015 02:37 PM |
| Disabling content controls and protecting document sections. | Catty | Word VBA | 2 | 11-29-2013 05:10 AM |
| Protecting Word Document by restricting access permissions! | user | Word | 0 | 11-20-2008 01:21 PM |