输入Powerpoint时如何调整Excel VBA文本的大小?

时间:2018-11-29 21:42:37

标签: excel vba powerpoint

当前从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)

感谢您提供的所有帮助!

1 个答案:

答案 0 :(得分:0)

您可以使用“〜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(“给定名称”).Textframe.TextRange。〜=〜'