Results 1 to 3 of 3

Thread: Writing to Header and Footer while Changing Text Color

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #3
    Microsoft Word MVP 2003-2009 VBAX Guru gmaxey's Avatar
    Joined
    Sep 2005
    Posts
    3,411
    Location
    What version of Word? Have you considered using content controls instead of Formfields?

    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    Dim oCC As ContentControl
    Dim oRng As Word.Range
    Dim strPW As String
      strPW = "topics"
      Select Case ContentControl.Title
        Case "Subject" 'The "Subject" Dropdown CC in document.
          If Not ActiveDocument.ProtectionType = wdNoProtection Then
            ActiveDocument.Unprotect Password:=strPW
          End If
          Set oCC = ActiveDocument.SelectContentControlsByTitle("HF Subject").Item(1) 'Richtext CC in Header
          Select Case True
            Case ContentControl.ShowingPlaceholderText:
              oCC.Range.Text = vbNullString
            Case ContentControl.Range.Text = "MATH"
              oCC.Range.Text = "Subject: MATH"
              Set oRng = oCC.Range
              oRng.Start = oRng.Start + 9
              oRng.Font.ColorIndex = wdRed
            Case ContentControl.Range.Text = "ENGLISH"
              oCC.Range.Text = "Subject: ENGLISH"
              Set oRng = oCC.Range
              oRng.Start = oRng.Start + 9
              oRng.Font.ColorIndex = wdBlue
            Case ContentControl.Range.Text = "SOCIAL STUDIES"
              oCC.Range.Text = "Subject: SOCIAL STUDIES"
              Set oRng = oCC.Range
              oRng.Start = oRng.Start + 9
              oRng.Font.ColorIndex = wdGreen
          End Select
          'Richtext CC in Footer
          ActiveDocument.SelectContentControlsByTitle("HF Subject").Item(2).Range.FormattedText = oCC.Range.FormattedText
          ActiveDocument.Protect wdAllowOnlyReading, , strPW
      End Select
    lbl_Exit:
      Exit Sub
    End Sub
    Attached Files Attached Files
    Greg

    Visit my website: http://gregmaxey.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •