【问题标题】:How to change color of specific word(s) from input box vba powerpoint vba beginner如何从输入框更改特定单词的颜色 vba powerpoint vba初学者
【发布时间】:2016-10-02 22:17:32
【问题描述】:

我对 vba 很陌生(昨天才开始),但想使用代码来节省一些时间来填写 powerpoint 表格。到目前为止,我已经弄清楚了如何生成一个带有结果文本框的输入框,并在只输入一个单词并且匹配的情况下更改字体颜色。然而,这并不完全符合我的需要。

就我而言,用户输入约定是“Word1-Word2-Word3-Word4-Word5”。例如,“红-黄-橙-绿-蓝”。我想让红色变成红色,黄色变成黄色,橙色变成橙色,等等。破折号将保持黑色。输入可以是任何顺序,并非所有部分都存在(即“黄-红-绿-蓝-橙”或“红-蓝-绿”可能发生),但需要保留颜色编码。

<here is where I should put my current code that doesn't exactly fit my needs>

谁能帮我解决这个问题?

【问题讨论】:

  • 这不是代码编写服务。到目前为止你尝试了什么?发布您的代码!运行时发生了什么?你期望会发生什么?您具体遇到了什么问题?
  • 向我们展示您的代码!
  • 在问下一个问题之前请阅读stackoverflow.com/help/how-to-ask

标签: vba powerpoint


【解决方案1】:

正如所指出的,我们不是代码编写服务。但是,一旦您提供了基本代码,您仍然可能会在 PPT 处理文本的方式上遇到一些奇怪的问题。所以让我们把其中的一些短路。

假设您将获取用户提供的文本字符串并将其添加到幻灯片上的文本框中。下面的例子假设文本框被选中;您的代码将需要插入一个新文本框并在变量中获取对它的引用(在本例中为 oSh)。

Sub Example()
' This looks for the word "red" in the currently selected
' shape's text and if found, turns it red.

    Dim oSh As Shape
    Dim oRng As TextRange

    ' Get a reference to the currently selected shape
    ' For what you're doing, you'd need slightly different code
    Set oSh = ActiveWindow.Selection.ShapeRange(1)

    ' Get a reference to the text range that contains the word "red"
    Set oRng = oSh.TextFrame.TextRange.Find("red")

    ' Change the color of the text range containing the word "red"
    ' RealWorld Notes:
    ' Test to see if oRng Is Nothing ... which it'll be if there's 
    ' no word "red" in the string
    ' You'll need to deal with capitalization: "red" vs "Red" etc.        
    oRng.Font.Color.RGB = RGB(255, 0, 0)

End Sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-17
    • 1970-01-01
    • 1970-01-01
    • 2017-07-13
    • 2014-08-26
    相关资源
    最近更新 更多