【问题标题】:How do I format the colors and fonts in a VBA textbox in ppt如何在ppt的VBA文本框中格式化颜色和字体
【发布时间】:2013-06-21 11:25:09
【问题描述】:

我在 ppt 中创建了一个宏来插入带有明年日期的文本框,因为内置的插入日期仅适用于当年:

Sub displaynextyear()

present = Year(Date)

ActivePresentation.Slides(3).Shapes.AddShape _
(Type:=msoTextOrientationHorizontal, Left:=500, Top:=150, Width:=100, Height:=25) _
.TextFrame.TextRange.Text = "{" & present + 1 & "}"

End Sub

它可以工作,但我想对其进行微调,使其与幻灯片的背景颜色、字体大小等相匹配。每次我尝试插入可能的格式参数时,都会收到错误消息。 请问如何自定义?以及如何让它在打开 ppt 演示文稿时自动运行?

谢谢! 约翰

【问题讨论】:

  • 演示文稿打开时,PowerPoint 不会自动运行代码。如果您想在幻灯片放映开始时执行代码,有一个相对简单的解决方法;如果您想在演示文稿打开时运行代码,可以这样做,但前提是您已经编写并安装了一个插件来实现它。

标签: vba textbox powerpoint


【解决方案1】:

.Background 方法使形状背景与其幻灯片匹配。

Sub displaynextyear()
    Dim shp As Shape

    present = Year(Date)

    Set shp = ActivePresentation.Slides(3).Shapes.AddShape _
    (Type:=msoTextOrientationHorizontal, Left:=500, Top:=150, Width:=100, Height:=25)
    shp.TextFrame.TextRange.Text = "{" & present + 1 & "}"

    shp.TextFrame.TextRange.Font.Size = 20
    shp.Fill.Background     'match the slide background

End Sub

这适用于 PowerPoint 2010,因此很可能也适用于 PPt 2007。

注意:我们无法在 PPt 2010 中记录宏来帮助查找方法/属性。

【讨论】:

    猜你喜欢
    • 2012-09-16
    • 2020-06-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-15
    • 1970-01-01
    相关资源
    最近更新 更多