vba Powerpoint 宏将单个文本框居中对齐以滑动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26040586/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Powerpoint Macro to center align a single text box to slide
提问by Abby
I am trying to center align the text boxes in a large presentation. Each slide contains various shapes, but only has one text box with text in it, and I would like that text box aligned to the center of the slide. At the moment, I have a line of code that will make the text center aligned within its own text box, but I was wondering if there was a way of making the text box in the middle of the slide?
我正在尝试将大型演示文稿中的文本框居中对齐。每张幻灯片都包含各种形状,但只有一个带有文本的文本框,我希望该文本框与幻灯片的中心对齐。目前,我有一行代码可以使文本中心在其自己的文本框中对齐,但我想知道是否有办法在幻灯片中间制作文本框?
Sub TextSize()
Dim oSl As Slide
Dim oSh As Shape
With ActivePresentation
For Each oSl In .Slides
For Each oSh In oSl.Shapes
With oSh
If .HasTextFrame Then
If .TextFrame.HasText Then
.TextFrame.TextRange.Font.Size = 26.5
' change the code to make the text box centre aligned to the slide
.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
End If
End If
End With
Next
Next
End With
End Sub
回答by Steve Rindsberg
Gopal's pointed you in the right direction. After your code to center the text, add this:
Gopal 为您指明了正确的方向。在使文本居中的代码之后,添加以下内容:
.Left = ActivePresentation.PageSetup.SlideWidth / 2 - .Width / 2
.Top = ActivePresentation.PageSetup.SlideHeight / 2 - .Height / 2
回答by gkb
Although not mentioned, but in case you are adding the textboxes on the slide through VBA code (as explained in thisdocumentation), then I guess textboxes do not have a property to directly get aligned to the slide in a particular fashion(in your case centrally).
虽然没有提到,但如果您通过 VBA 代码在幻灯片上添加文本框(如本文档中所述),那么我猜文本框没有以特定方式直接与幻灯片对齐的属性(在您的情况下)集中)。
Having said that, I would also point towards a possible workaround which may be to set the Topand the Leftproperties of the textboxes in a ratio proportional to the slide'sheightand widthchosen for your presentation.
话虽如此,我还将指出一种可能的解决方法,即以与为演示文稿选择的幻灯片的高度和宽度成比例的比例设置文本框的Top和Left属性。
This I think should centrally align the textboxes.
我认为这应该集中对齐文本框。