【问题标题】:Change Content Control Properties Text Style based on drop-down value selection根据下拉值选择更改内容控件属性文本样式
【发布时间】:2019-02-27 22:29:55
【问题描述】:

目前我有一个宏可以根据选择的下拉列表内容控件值更改.BackgroundPatternColor。它适用于整个表格单元格。

下面的代码 + 屏幕截图。

Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)
With ContentControl.Range
    If ContentControl.Title = "Status" Then
        Select Case .Text
            Case "RED"
                .Cells(1).Shading.BackgroundPatternColor = RGB(227, 36, 27)
                .Cells(1).Range.Font.TextColor = wdColorWhite
            Case "AMBER"
                .Cells(1).Shading.BackgroundPatternColor = RGB(251, 171, 24)
                .Cells(1).Range.Font.TextColor = wdColorBlack
            Case "GREEN"
                .Cells(1).Shading.BackgroundPatternColor = RGB(110, 190, 74)
                .Cells(1).Range.Font.TextColor = wdColorWhite
            Case Else
                .Cells(1).Shading.BackgroundPatternColor = wdColorAutomatic
        End Select
    End If
End With
End Sub

由于您无法通过 VBA 更改 MS Word 中的文本突出显示颜色,我发现我可以通过更改属性中内容控件的样式格式来获得所需的外观。

属性 -> +NewStyle -> 格式 -> 边框...

只有这样我才能使用自定义颜色获得所需的“突出显示文本”外观,而不是更改表格单元格的整个背景。

我想要的是这样的:

我为每种选择类型创建了单独的样式。

但是,我不知道如何根据 MS Word 中的当前下拉值选择来更改内容控件属性文本样式。

请帮忙。谢谢

【问题讨论】:

    标签: vba ms-word


    【解决方案1】:

    也许:

    Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
    With CCtrl
      If .Title = "Status" Then
        With .Range
          Select Case .Text
            Case "RED"
              .Shading.BackgroundPatternColorIndex = wdRed
              .Font.ColorIndex = wdWhite
            Case "AMBER"
              .Shading.BackgroundPatternColorIndex = wdDarkYellow
              .Font.ColorIndex = wdColorBlack
            Case "GREEN"
              .Shading.BackgroundPatternColorIndex = wdBrightGreen
              .Font.ColorIndex = wdWhite
            Case Else
              .Shading.BackgroundPatternColorIndex = wdAuto
          End Select
        End With
      End If
    End With
    End Sub
    

    【讨论】:

      猜你喜欢
      • 2014-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 2017-03-30
      • 2014-09-24
      • 2011-09-04
      相关资源
      最近更新 更多