有没有一种方法可以向Word VBA组合框文本条目的一部分添加粗体样式?

时间:2019-12-12 14:16:55

标签: vba combobox ms-word styles

我有一个带有用户窗体组合框的启用了宏的单词模板,我需要插入其中的一些文本以在文档上以粗体显示。我尝试仅添加html元素(例如粗体html),但它们没有起作用。插入文本时,是否可以设置样式?

'Populate standard_response
  With standard_response
  .AddItem "<b><u>You were not provided written notice of charge.</u></b> You signed for and received a copy of the offense report detailing the charge against you on 00/00/00.  You also verbally acknowledged during your disciplinary hearing on 00/00/00 that you received a copy of the offense report"
   .AddItem "You were not provided at least 24 hours to prepare before hearing.  You received a copy of the offense report detailing the charge against you on 00/00/00.  Your disciplinary hearing was conducted on 00/00/00, therefore, you had at least twenty-four hours to prepare for the hearing.   "
   .AddItem "You were not permitted the opportunity to present relevant witness/es or to submit relevant written witness statements.  During the active phase of the investigation you did not wish to call any witnesses as verified by your signature on the 'Disciplinary Coordinator's Report' on 7/19/19.  You were also provided with the opportunity to present relevant written witness statements at your disciplinary hearing but did not do so."
   .AddItem "There was no written statement of evidence utilized for a determination of guilt.  Section III of the 'Disciplinary Hearing Report' cites a written statement of evidence relied on for the finding of guilt that identifies the offending behavior and is compliant with Section VII.D.2. of OP-060125, 'Offender Disciplinary Procedures.' "
  End With

1 个答案:

答案 0 :(得分:0)

可以运行一个宏,该宏将突出显示部分文本,具体取决于所使用的下拉选项。但是更简单的方法包括:1-将其另存为模板中的“自动图文集/构建块”,然后使用下拉选项插入相关文本块,或2-格式化所有选项,将其标记为隐藏文本,然后仅显示所选的响应。展示了所有3种情况:

Private Sub CommandButton1_Click()
    Dim oTextRange As Range
    Set oTextRange = ActiveDocument.Bookmarks("Response").Range
    Select Case standard_response.value
        Case "Item 1"
            With oTextRange
                .Text = standard_response.value
                .MoveEnd Unit:=wdWord, Count:=30
                .Font.Bold = True
            End With
        Case "Item 2"
            ActiveDocument.AttachedTemplate.AutoTextEntries("Response1").Insert Where:=oTextRange, RichText:=True
        Case "Item 3"
            ActiveDocument.Bookmarks("Response1").Range.Font.Hidden = False
        Case Else
    End Select
End Sub