-
I have modified the protection code as follows:
[vba]If ActiveDocument.ProtectionType <> wdNoProtection Then
ActiveDocument.Unprotect Password:="12345"
End If
Call FlagEmptyCCs
If ActiveDocument.ProtectionType = wdNoProtection Then
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="12345"
End If[/vba]
The previous code would unlock the document and the document would stay unlocked. The second section of code needed to be changed to see if the doucument was unlocked and if it was, then lock it. The way the code was writting was asking if the document was locked (ProtectionType <> wdNoProtection) to then lock it. A bit redundant.
BREAK
Greg,
The reason I had the drop downs the way I did was because I cannot come up with the proper code for the ClearFields macro to clear the drop down list without resetting its placeholder text back to Choose an Item.
The best I could come up with was to have Select One be one of the list entries and to have code that would set each drop down list back to the first list entry.
You helped me with the code in a previous thread linked below.
http://www.vbaexpress.com/forum/showthread.php?t=38257
I have tried modifying your ClearFields code by adding another case for drop down lists as shown below.
However, when this code runs I get a runtime error 6124 saying I'm not allowed to edit this selection because it is proteced.
The debugger highlights the second oCC.Range.Text = "" code that I added.
I have tried including the unprotect code at the beginning of the macro but that doesn't fix the issue. Also I'm not sure why I don't get the same error for the first case with Rich Text controls. They clear fine.
[vba]Sub ClearFields()
Dim oILS As InlineShape
Set oCCs = ActiveDocument.Range.ContentControls
Dim i As Long
For Each oCC In oCCs
Select Case oCC.Type
Case wdContentControlRichText
oCC.Range.Text = ""
End Select
Select Case oCC.Type
Case wdContentControlDropdownList
oCC.Range.Text = ""
End Select
Next oCC
For Each oILS In ActiveDocument.InlineShapes
If oILS.Type = wdInlineShapeOLEControlObject Then
If TypeOf oILS.OLEFormat.Object Is MSForms.OptionButton Then
oILS.OLEFormat.Object.Value = False
End If
End If
Next
Call FlagEmptyCCs
End Sub[/vba]
I love how you take 2 steps forward and then one back. This is frustrating.
In a bit of good news, I did figure out how to not highlight specific fields by adding the code below. Now I just need to work with the conditional formatting issue.
[VBA]Sub FlagEmptyCCs()
Dim oTbl As Word.Table
Dim oCell As Word.Cell
Dim oCC As ContentControl
Dim oCCs As ContentControls
Set oTbl = ActiveDocument.Tables(1)
For Each oTbl In ActiveDocument.Tables
For Each oCell In oTbl.Range.Cells
If oCell.Range.ContentControls.Count > 0 Then
For Each oCC In oCell.Range.ContentControls
If oCC.Tag = "Date1" Then
oCC.Range.Shading.BackgroundPatternColor = wdColorWhite
Else
If oCC.Tag = "Date2" Then
oCC.Range.Shading.BackgroundPatternColor = wdColorWhite
Else
If oCC.Tag = "Date3" Then
oCC.Range.Shading.BackgroundPatternColor = wdColorWhite
Else
If oCC.ShowingPlaceholderText = True Then
'oCell.Shading.BackgroundPatternColor = wdColorAutomatic 'wdColorRose
'or
oCC.Range.Shading.BackgroundPatternColor = wdColorRose
End If
End If
End If
End If
Next oCC
End If
Next oCell
Next oTbl
End Sub[/VBA]
Last edited by g8r777; 08-02-2011 at 03:12 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules