【问题标题】:Is there a way to add bold styling to part of a Word VBA combobox text entries?有没有办法为 Word VBA 组合框文本条目的一部分添加粗体样式?
【发布时间】:2020-04-05 23:03:53
【问题描述】:

我有一个启用宏的 word 模板,其中包含一个用户表单组合框,我需要它插入的一些文本在文档上显示为粗体。我尝试只添加 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

【问题讨论】:

  • 用户窗体和 Word 文档都没有在其原生格式中使用 HTML 样式。您的代码示例似乎试图将组合框显示的一部分设置为粗体,而您的文本表明您希望最终文档中的文本为粗体。后者是可能的,但不是前者。
  • 感谢您的信息

标签: vba combobox ms-word styles


【解决方案1】:

可以运行一个宏来突出显示部分文本,具体取决于所使用的下拉选项。但更简单的方法包括 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

【讨论】:

  • 谢谢。效果很好。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-02-22
  • 1970-01-01
  • 2023-04-10
  • 2013-01-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多