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:
I have written this, but I have a problem with footers on different pages:Selection.Range.ContentControls.Add (wdContentControlGroup) Selection.ParentContentControl.LockContentControl = True
Also another approach did not work: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
as I do not know if I have to use wdHeaderFooterFirstPage or wdHeaderFooterPrimaryPage in the section 0,1,2,..and so on..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
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


Reply With Quote

