Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba Powerpoint宏居中对齐单个文本框和幻灯片_Vba_Textbox_Alignment_Powerpoint_Center - Fatal编程技术网

Vba Powerpoint宏居中对齐单个文本框和幻灯片

Vba Powerpoint宏居中对齐单个文本框和幻灯片,vba,textbox,alignment,powerpoint,center,Vba,Textbox,Alignment,Powerpoint,Center,我正在尝试将大型演示文稿中的文本框居中对齐。每张幻灯片包含各种形状,但只有一个文本框,其中包含文本,我希望该文本框与幻灯片的中心对齐。目前,我有一行代码,使文本中心在自己的文本框中对齐,但我想知道是否有一种方法使文本框在幻灯片的中间? Sub TextSize() Dim oSl As Slide Dim oSh As Shape With ActivePresentation For Each oSl In .Slides For Each oS

我正在尝试将大型演示文稿中的文本框居中对齐。每张幻灯片包含各种形状,但只有一个文本框,其中包含文本,我希望该文本框与幻灯片的中心对齐。目前,我有一行代码,使文本中心在自己的文本框中对齐,但我想知道是否有一种方法使文本框在幻灯片的中间?

    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

虽然没有提到,但如果您是通过VBA代码在幻灯片上添加文本框(如文档中所述),那么我猜文本框没有以特定方式直接与幻灯片对齐的属性(在您的示例中)

话虽如此,我还想指出一种可能的解决方法,即按照幻灯片高度和宽度的比例设置文本框的顶部和左侧属性


我认为这应该使文本框居中对齐。

Gopal为您指出了正确的方向。在将文本居中的代码之后,添加以下内容:

.Left = ActivePresentation.PageSetup.SlideWidth / 2 - .Width / 2
.Top = ActivePresentation.PageSetup.SlideHeight / 2 - .Height / 2

非常感谢你的时间和建议。如果字体太大,形状是桌子。这不行!知道如何修复它吗?代码回答了将文本框居中的请求。桌子是完全不同的事情。开始一个新的线程,无论你有什么代码到目前为止;如果可能的话,附上一张幻灯片的截图。非常感谢你,正如你所建议的,我现在已经学会了使用比例来对齐。