View Single Post
 
Old 11-22-2017, 05:11 AM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,369
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

Try the following code. Do be careful, though, as it both deletes the content control title and converts the dropdown to a text content control as part of the 'locking' process you wanted. For the output, you'll need a text content control in whichever of the Section's headers you don't have the content control in. The code works equally well with or without a 'different first page' and/or 'different odd and even' page setup.

The other thing to be aware of is that, with content controls in the header, you need to click somewhere else in the header for the macro to run.
Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
Dim StrDetails As String, HdFt As HeaderFooter
With CCtrl
  If .Title = "Sector" Then
    If .ShowingPlaceholderText = True Then Exit Sub
    .Title = ""
    StrDetails = .Range.Text
    .LockContentControl = False
    .Type = wdContentControlText
    For Each HdFt In .Range.Sections(1).Headers
      With HdFt
        If .Exists Then
          If .Range.ContentControls.Count = 1 Then
            With .Range.ContentControls(1)
              .LockContents = False
              .Range.Text = StrDetails
              .LockContents = True
              .LockContentControl = True
            End With
          End If
        End If
      End With
    Next
  End If
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote