vba 如何格式化ppt中VBA文本框中的颜色和字体

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17284216/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 21:50:55  来源:igfitidea点击:

How do I format the colors and fonts in a VBA textbox in ppt

vbatextboxpowerpoint

提问by user2517718

I've created a macro in ppt to insert a text box with next year's date, since the built-in insert date is only for the current year:

我在 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

It works, but I want to fine-tune it so it matches the slide's background color, font size, etc. Every time I try to insert likely formatting parameters, I get error messages. How do I customize, please? And how would I get it to run automatically whenever the ppt presentation is opened?

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

Thanks! John

谢谢!约翰

回答by Andy G

The .Backgroundmethod makes a shapes background match that of its slide.

.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

This works in PowerPoint 2010, so most likely in PPt 2007 as well.

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

Note: We cannot record macros in PPt 2010 to help find methods/properties.

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