首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >VBA Powerpoint文本框对齐方式

VBA Powerpoint文本框对齐方式
EN

Stack Overflow用户
提问于 2012-07-18 20:34:05
回答 2查看 25.4K关注 0票数 4

我正在使用Powerpoint 2007,我想编写一个宏来制作幻灯片中的文本框。

但是,默认情况下文本框中的文本是居中对齐的。我想左对齐,但我不知道该怎么做。如何更改此文本框的对齐方式?

这是我的代码。

代码语言:javascript
运行
复制
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
EN

回答 2

Stack Overflow用户

发布于 2012-07-18 22:44:48

首先,选择代码中的任何内容或依赖于当前选择通常不是一个好的做法,因为它可能会使您的代码慢几个数量级。

取而代之的是像这样的东西:

代码语言:javascript
运行
复制
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
票数 6
EN

Stack Overflow用户

发布于 2012-09-02 04:55:03

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

代码语言:javascript
运行
复制
oPPShape.TextFrame.TextRange.ParagraphFormat.Alignment = msoAlignLeft

只是对你和史蒂夫的帖子的评论。如果您真的使用这些代码和对象进行后期绑定,那么您还需要记住定义msoTextOrientationHorizontal等PowerPoint库中的常量。当您从项目中删除PPT引用时,您很快就会发现哪些常量被省略了。与Excel一样,将宏分发给不同版本的用户最好使用后期绑定,其中Office产品引用是独立于版本的。

代码语言:javascript
运行
复制
'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.

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11541475

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档