Consulting

Results 1 to 3 of 3

Thread: Word "Compile error: Method of data member not found"

  1. #1

    Word "Compile error: Method of data member not found"

    Hi

    I've just added the following code to my word document to change the colour and highlighting of selections in my drop down list. However, when I try to save the document I get the error "Comile error: Method of data member not found". The line it highlights is the first in the below code:

    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
    With ContentControl
    If ContentControl.Title = "Test" Then
    Select Case .Range.Text
    Case "Blue"
    .Font.Color = wdColorBlue
    .Font.Underline
    .Shading.BackgroundPatternColor = wdColorAutomatic
    Case Else
    .Font.Color = wdColorBlack
    .Shading.BackgroundPatternColor = wdColorYellow
    End Select
    End If
    End With
    End Sub

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    4,435
    Location
    Font attributes and shading are not properties of the ContentControl object. Try:
    Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
    With CCtrl
      If .Title <> "Test" Then Exit Sub
      With .Range
        Select Case .Text
          Case "Blue"
            .Font.Color = wdColorBlue
            .Font.Underline = wdUnderlineSingle
            .Shading.BackgroundPatternColor = wdColorAutomatic
          Case Else
            .Font.Color = wdColorBlack
            .Font.Underline = wdUnderlineNone
            .Shading.BackgroundPatternColor = wdColorYellow
        End Select
      End With
    End With
    End Sub
    Cheers
    Paul Edstein
    [Fmr MS MVP - Word]

  3. #3
    While Paul has identified the problem, I would recommend adding a trap to ensure that the placeholder text is not displayed e.g.

    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)    With ContentControl
            If ContentControl.TITLE = "Test" Then
                If .ShowingPlaceholderText = False Then
                    Select Case .Range.Text
                        Case "Blue"
                            .Range.Font.Color = wdColorBlue
                            .Range.Font.Underline = wdUnderlineSingle
                            .Range.Shading.BackgroundPatternColor = wdColorAutomatic
                        Case Else
                            .Range.Font.Color = wdColorBlack
                            .Range.Font.Underline = wdUnderlineNone
                            .Range.Shading.BackgroundPatternColor = wdColorYellow
                    End Select
                Else
                    .Range.Font.Color = wdColorAutomatic
                    .Range.Font.Underline = wdUnderlineNone
                    .Range.Shading.BackgroundPatternColor = wdColorWhite
                End If
            End If
        End With
    End Sub
    Graham Mayor - MS MVP (Word) 2002-2019
    Visit my web site for more programming tips and ready made processes
    http://www.gmayor.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
  •