Hello,
i would like to have 2 functions to lock and unlock Contentcontrols in all Footers in my Word Document.
The syntax to group and lock is:
Selection.Range.ContentControls.Add (wdContentControlGroup)
Selection.ParentContentControl.LockContentControl = True
I have written this, but I have a problem with footers on different pages:
Application.ScreenUpdating = False
Dim Sctn As Section, HdFt As HeaderFooter
With ActiveDocument
For Each Sctn In .Sections
MsgBox (Sctn.Index)
For Each HdFt In Sctn.Headers
With HdFt
If .LinkToPrevious = False Then
With .Range
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
For Each fieldX In .Fields
If InStr(1, fieldX.Code.Text, "KLASSIFIZIERUNG", 1) > 0 Then
fieldX.Select
Selection.Range.ContentControls.Add (wdContentControlGroup)
Selection.ParentContentControl.LockContentControl = True
End If
Next fieldX
End With
End If
End With
Next
For Each HdFt In Sctn.Footers
With HdFt
If .LinkToPrevious = False Then
With .Range
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
For Each fieldX In .Fields
If InStr(1, fieldX.Code.Text, "KLASSIFIZIERUNG", 1) > 0 Then
fieldX.Select
Selection.Range.ContentControls.Add (wdContentControlGroup)
Selection.ParentContentControl.LockContentControl = True
End If
Next fieldX
End With
End If
End With
Next
Next
End With
Also another approach did not work:
Dim oHFKL As HeaderFooter
Dim fieldX As Field
ActiveWindow.ActivePane.View.SeekView = wdSeekFirstPageFooter
For Each fieldX In ActiveDocument.Sections(0).Footers(wdHeaderFooterFirstPage).Range.Fields
If InStr(1, fieldX.Code.Text, "KLASSIFIZIERUNG", 1) > 0 Then
fieldX.Select
Selection.Range.ContentControls.Add (wdContentControlGroup)
Selection.ParentContentControl.LockContentControl = True
End If
Next fieldX
as I do not know if I have to use wdHeaderFooterFirstPage or wdHeaderFooterPrimaryPage in the section 0,1,2,..and so on..
I also get a display problem (ActiveWindow.ActivePane.View.Type switches to 1 and does not remain in status 3) when using this function above.
The fields in my footers are VBA Docvariables with "KLASSIFIZIERUNG" (engl: classification) within, so thats why I check the field.Code.Text by Instr()
Any help? Any ideas?
best regards,
Andreas