取消突出显示文本(并保留所有其他字体设置) [英] Unhighlighting text (and preserve all other font settings)
本文介绍了取消突出显示文本(并保留所有其他字体设置)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
感谢两篇帖子(here和here),我知道如何使用VBA代码突出显示PowerPoint中的文本框文本。
但是,未突出显示文本的问题仍未解决。我尝试将未突出显示的文本框的属性设置为TextRange2.Font(例如.TextFrame2.TextRange.Font.Highlight.SchemeColor = -2
),但在尝试时收到错误(键入的值超出范围)。
请问有人能帮我解决这个问题吗?
TextRange2.Font.Highlight.RGB = RGB(255, 255, 175)
)文本框的格式更改,因此字体颜色从我的预设白色更改为黑色,字体大小变小。有没有办法保留文本框的原始设置?发生这种情况是因为访问了.TextRange2而不是.TextRange吗?
谢谢您的帮助!
在PowerPoint2019/365中,可以使用内置MSOMSO365来取消突出显示(";TextHighlightColorPickerLicensed";.)。在PowerPoint2019/推荐答案中,可以使用内置MSO365来取消突出显示此代码示例说明如何取消突出显示所选形状中的文本。它通过以编程方式调用命令栏突出显示按钮来查找包含突出显示的运行、选择它们并删除突出显示。
前提条件:PowerPoint 2019或365。演示文稿必须使用窗口打开。
Option Explicit
Sub UnhighlightTextInSelectedShape()
Dim sh As Shape
For Each sh In ActiveWindow.Selection.ShapeRange
UnhighlightTextInShape sh
Next
End Sub
Sub UnhighlightTextInShape(sh As Shape)
On Error GoTo Finish
Dim highlightIsRemoved As Boolean
Dim tf As TextFrame2
Set tf = sh.TextFrame2
Do
Dim r As TextRange2
highlightIsRemoved = True
For Each r In tf.TextRange.Runs
If r.Font.Highlight.Type <> msoColorTypeMixed Then
' Indicate that text contains highlighting
highlightIsRemoved = False
' The text to un-highlight must be selected
r.Select
If Application.CommandBars.GetEnabledMso("TextHighlightColorPickerLicensed") Then
' This Mso toggles highlighting on selected text.
' That is why selection must contain highlight of the same type
Application.CommandBars.ExecuteMso ("TextHighlightColorPickerLicensed")
' Unhighlighting May invalidate number of runs, so exit this loop
Exit For
Else
Exit Do
End If
End If
Next
Loop Until highlightIsRemoved
Finish:
If Not highlightIsRemoved Then
MsgBox "Unhighlighting is not supported"
End If
End Sub
有时,Application.CommandBars.ExecuteMso()方法提供对PowerPoint API不可用功能的访问。
MsoId显示在PowerPoint选项窗口的工具提示文本中:
这篇关于取消突出显示文本(并保留所有其他字体设置)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文