PDA

View Full Version : [SOLVED:] Word "Compile error: Method of data member not found"



ericagrace
11-25-2019, 05:47 PM
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

macropod
11-25-2019, 08:09 PM
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

gmayor
11-25-2019, 10:30 PM
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