2016-09-19 23 views
0

所以我有這行代碼,它只適用於1 ppt文件。中心最頂級的文本框VBA powerpoint

ActiveWindow.Selection.ShapeRange.TextFrame.TextRange.ParagraphFormat.Alignment=ppAlignCenter 

我如何使這個工作在與VBA相同的文件夾中的所有PowerPoint文件?所以它知道它選擇了最頂級的TextFrame,然後AlignCenters它。

甚至當所有的PPT中是開放的,如果這是更容易..

回答

0

這將選擇最接近定位在幻燈片上的形狀:

Option Explicit 

' Selects the shape that support text which is closest to the top of the slide 
' Written by Jamie Garroch of YOUpresent Ltd (http://youpresent.co.uk) 
Sub SelectHigestTextShape() 
    Dim oSld As Slide 
    Dim oShp As Shape, oShpTop As Shape 
    Dim sShpTop As Single 

    On Error Resume Next 
    Set oSld = ActiveWindow.View.Slide 
    If Err Then Exit Sub 
    On Error GoTo 0 

    ' Set the top to the bottom of the slide 
    sShpTop = ActivePresentation.PageSetup.SlideHeight 

    ' Check each shape on the slide is positioned above the stored position 
    ' Shapes not supporting text and placeholders are ignored 
    For Each oShp In oSld.Shapes 
    If oShp.Top < sShpTop And oShp.HasTextFrame And Not oShp.Type = msoPlaceholder Then 
     sShpTop = oShp.Top 
     Set oShpTop = oShp 
    End If 
    Next 

    ' Select the topmost shape 
    If Not oShpTop Is Nothing Then oShpTop.Select msoTrue 

    ' Clean up 
    Set oSld = Nothing 
    Set oShp = Nothing 
    Set oShpTop = Nothing 
End Sub 
+0

感謝這個作品,但似乎當我說它應該爲所有打開的工作簿執行此操作時,它不起作用。 – Probs

相關問題