【问题标题】:How do I format individual lines in a textbox via Microsoft PowerPoint macros?如何通过 Microsoft PowerPoint 宏格式化文本框中的单行?
【发布时间】:2017-03-27 15:03:08
【问题描述】:

我想要一个文本框,其中第一行和随后的文本行具有不同的格式,但它们必须在同一个文本框中。这是我目前拥有的,它将相同的格式应用于所有文本。

Sub geberateSlide() 
  ...
  With currSlide.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
  Left:=0, Top:=0, Width:=headerWidth, Height:=headerHeight)
    .TextFrame.TextRange.Text = "Test Box" & vbCrLf & "Description"
    .TextFrame.AutoSize = ppAutoSizeNone
    .Height = headerHeight
    .Line.ForeColor.RGB = RGB(0,0,0)
    .Line.Visible = True
  End With
...
End Sub

文本应为 Arial 8。第 1 行应为黑色和粗体,而后续文本应为蓝色。

【问题讨论】:

    标签: vba powerpoint powerpoint-2013


    【解决方案1】:

    .TextFrame.TextRange.Lines(0, 1) 将针对第一行。

    %300 缩放

    With currSlide.Shapes.AddTextbox(Orientation:=msoTextOrientationHorizontal, _
                                     Left:=0, Top:=0, Width:=headerWidth, Height:=headerHeight)
        .Height = headerHeight
        .TextFrame.AutoSize = ppAutoSizeNone
        With .TextFrame.TextRange
            .Text = "Test Box" & vbCrLf & "Description"
            With .Font
                .Color = vbBlue
                .Size = 8
                .Name = "Arial"
            End With
    
            With .Lines(1).Font
                .Color = vbBlack
                .Bold = msoTrue
            End With
        End With
    End With
    

    【讨论】:

    • 感谢您接受我的回答!这是一个有趣的问题。我通常不使用 PowerPoint,但我对 VBA 模型有一个大致的了解;所以并不难弄清楚。
    • 只是一个注释,0 表示旧版 TextRange 对象的整个段落。所以你可以用 .Lines(1) 得到同样的结果
    • 另外,TextRange 是旧对象,因此您需要使用 TextRange2 来访问较新的文本样式。
    • @ShyamPillai 谢谢我更新了.Lines(1). I had trouble trying to implement TextRange2. Maybe it is because for some reason my Office 360 runs in 32bit mode. In any case, TextRange` 是旧版,但仍受支持。 TextRange2 仅适用于 Office 2013 及更高版本,还有很多人仍在使用 Office 2007。
    • 是的,除非您想使用新样式进行格式化,否则可以使用 TextRange。此外,TextRange2 是在 2007 年而不是 2013 年推出的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-02
    • 2012-09-16
    • 2014-11-20
    • 2016-12-20
    相关资源
    最近更新 更多