我正在使用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
发布于 2012-07-18 22:44:48
首先,选择代码中的任何内容或依赖于当前选择通常不是一个好的做法,因为它可能会使您的代码慢几个数量级。
取而代之的是像这样的东西:
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
发布于 2012-09-02 04:55:03
我相信您的问题的答案在于Shape.TextFrame.TextRange
对象属性
oPPShape.TextFrame.TextRange.ParagraphFormat.Alignment = msoAlignLeft
只是对你和史蒂夫的帖子的评论。如果您真的使用这些代码和对象进行后期绑定,那么您还需要记住定义msoTextOrientationHorizontal
等PowerPoint库中的常量。当您从项目中删除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")
https://stackoverflow.com/questions/11541475
复制相似问题