【问题标题】:VBA PowerPoint textbox text alignmentVBA PowerPoint 文本框文本对齐
【发布时间】:2012-07-17 11:52:10
【问题描述】:

我正在使用 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

【问题讨论】:

  • 如果您的搜索引擎将您带到此处以在幻灯片上对齐文本框,请在此处查看此答案,该答案也适用于 PowerPoint:stackoverflow.com/a/53887373/1306012

标签: vba textbox powerpoint


【解决方案1】:

首先,选择代码中的任何内容或依赖当前选择通常都不是好的做法,因为它会使您的代码速度降低几个数量级。

取而代之的是这样的:

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

【讨论】:

    【解决方案2】:

    我相信你的问题的答案在Shape.TextFrame.TextRange对象属性中

    oPPShape.TextFrame.TextRange.ParagraphFormat.Alignment = msoAlignLeft
    

    只是对你和史蒂夫的帖子的评论。如果您确实使用此代码和对象进行后期绑定,您还需要记住从 PowerPoint 库中定义常量,例如 msoTextOrientationHorizontal。当您从项目中删除 PPT 引用时,您会很快发现哪些常量被遗漏了。 与 Excel 一样,将宏分发给具有不同版本的用户最好通过后期绑定来完成,其中 Office 产品引用与版本无关。

    'Bind to an existing or created instance of Microsoft Powerpoint
    Dim objPPTApp As Object
    On Error Resume Next
    Set objPPTApp = GetObject(, "Powerpoint.Application")
    If Err.Number <> 0 Then: Err.Clear: Set objPPTApp = CreateObject("Powerpoint.Application")
    

    More of late binding here.

    【讨论】:

      猜你喜欢
      • 2017-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-20
      相关资源
      最近更新 更多