VBA Powerpoint文本框对齐

use*_*778 4 powerpoint vba textbox powerpoint-vba

我正在使用Powerpoint 2007,我想编写一个宏,它在幻灯片中创建一个文本框.

但是,默认情况下,文本框中的文本与中心对齐.我想把它对齐,但我不知道该怎么做.如何更改此文本框的对齐?

这是我的代码.

Set objPPT = CreateObject("PowerPoint.Application")
Set SQ = objPPT.Presentation

......

SQ.Slides(i + 6).Shapes.AddTextbox(msoTextOrientationHorizontal, 50, 100, 600, 100).Select
objPPT.ActiveWindow.Selection.TextRange.Text = titre
Run Code Online (Sandbox Code Playgroud)

小智 5

首先,选择代码中的任何内容或依赖当前选择通常不是好的做法,只因为它可以减慢你的代码数量级.

相反,这样的事情:

Dim oSh as Object ' if you're using late binding, as Shape if early binding

Set oSh =  SQ.Slides(i + 6).Shapes.AddTextbox(msoTextOrientationHorizontal, 50, 100, 600, 100)
' notice that I've removed the .Select from the end of the line above

With oSh.TextFrame
  .TextRange.Text = "something"
  .TextRange.Paragraphs.ParagraphFormat.Alignment = ppAlignLeft
End With
Run Code Online (Sandbox Code Playgroud)