【问题标题】:How to resize Excel VBA text when inputting into Powerpoint?输入到 Powerpoint 时如何调整 Excel VBA 文本的大小?
【发布时间】:2018-12-05 21:23:25
【问题描述】:

目前从 Excel 表格中获取数据并将其输入到 Powerpoint 幻灯片中。我怎样才能从表格中调整下面的文本? Powerpoint 当前将其自动调整为 18 号字体。

Set ppSlide = ppPres.Slides.Add(1, ppLayoutBlank)

ppSlide.Shapes.AddTextbox(msoTextOrientationHorizontal, 100, 100, 200, 150).TextFrame.TextRange.Characters = "TEST " & Cells(Row, col + 1)

感谢您的所有帮助!

【问题讨论】:

  • 您是键入该代码还是从某个地方粘贴的?所有这些链接的点都在自找麻烦 - 声明一个 Shape 变量并将 Set 它声明为 Shapes.AddTextbox 的结果,然后你应该在 .TextFrame 上获得智能感知,你的问题应该自己回答。
  • BTW Excel 在这里几乎无关紧要,但不合格的 Cells 调用隐含地指的是 ActiveSheet 是什么 - 这是脆弱/容易出错的。考虑使用Worksheet 对象。

标签: excel vba powerpoint


【解决方案1】:

您可以使用“~TextRange.Charaters”。但它通常用于更改文本的某些部分。

~ TextRange.Characters(1, 2).Font.Bold = True ' sets the font of first 2 letters to bold style

相反,'~.TextRange' 或 '~.TextRange.Text' 就足够了。 并且可以使用'~ TextRange.Font.Size = xx'来设置文本的大小

应用 Mathieu Guindon 的建议后,您的代码将如下所示:

Sub test()
Dim Sht As Worksheet

Dim ppPres As PowerPoint.Presentation
Dim ppSlide As PowerPoint.Slide
Dim ppShape As PowerPoint.Shape

Set Sht = ThisWorkbook.Worksheets("Sheet1")

Set ppPres = ActivePresentation
Set ppSlide = ppPres.Slides.Add(1, ppLayoutBlank)
Set ppShape = ppSlide.Shapes.AddTextbox(msoTextOrientationHorizontal, 100, 100, 200, 150)
With ppShape
    .Name = "MyShape 1"
    With .TextFrame.TextRange
        .Text = "Test" & Sht.Cells(xRow, xColumn + 1) ' "Excel Cell Value"
        .Font.Size = 15
        .Font.Name = "Arial"
        .Font.Bold = True
        .Font.Color.RGB = RGB(0, 125, 255)
        'change first 2 letters to red color
        .Characters(1, 2).Font.Color.RGB = rgbRed
    End With
End With

End Sub

请给Powerpoint形状对象起个名字,这样以后你就可以用它的名字来控制对象了,比如'~.Shapes("Given name").Textframe.TextRange.~ = ~'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-29
    • 1970-01-01
    • 1970-01-01
    • 2017-03-19
    相关资源
    最近更新 更多