VBA PowerPoint 中的文本对齐

Text Alignment in VBA PowerPoint

有没有办法用宏从右到左对齐 PowerPoint 演示文稿中所有幻灯片上的文本(阿拉伯语)? (我正在使用 O365)。

在 Microsoft 示例中,我发现了这个:

Application.ActivePresentation.Slides(1).Shapes(2) _
    .TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignLeft

但我认为此示例将活动演示文稿幻灯片 1 中表格 2 的段落向左对齐。

所以我不知道如何处理所有 shapes/slides 类型。

专业的编码人员可能会改进它,但我认为这个应该对你有所帮助。如果您希望一次完成整个演示文稿,则只需 select 所有幻灯片,然后再单击它。我认为它比任何完整的演示解决方案都要好,因为它给了你选择的机会。

Option Explicit

Sub AlignAllTextLeft()
 
Dim osld As Slide
Dim oshp As Shape
Dim notesshp As Shape
Dim i As Long
Dim j As Long
Dim x As Long

    On Error GoTo ErMsg

    If MsgBox("You are going to change the text alignment of all text on all selected slides to left" & vbCrLf & "Continue?", vbYesNo) <> vbYes Then Exit Sub
 
For Each osld In ActiveWindow.Selection.SlideRange
 For Each oshp In osld.Shapes
 If oshp.HasTextFrame Then
 oshp.TextFrame2.TextRange.ParagraphFormat.Alignment = msoAlignLeft
 End If
 If oshp.HasTable Then
             For i = 1 To oshp.Table.Rows.Count
                For j = 1 To oshp.Table.Columns.Count
 oshp.Table.Rows.Item(i).Cells(j).Shape.TextFrame2.TextRange.ParagraphFormat.Alignment = msoAlignLeft
                 Next j
            Next i
 End If
 Next oshp

 For Each notesshp In osld.NotesPage.Shapes
 If notesshp.HasTextFrame Then
 notesshp.TextFrame2.TextRange.ParagraphFormat.Alignment = msoAlignLeft
 End If
 Next notesshp
 Next osld
 
For Each osld In ActiveWindow.Selection.SlideRange
    For Each oshp In osld.Shapes
    
        With oshp
            Select Case .Type
                Case Is = msoGroup
                For x = 1 To .GroupItems.Count
                    If .GroupItems(x).HasTextFrame Then
                         oshp.TextFrame2.TextRange.ParagraphFormat.Alignment = msoAlignLeft
                    End If
                Next x
            End Select
        End With
    Next oshp
    Next

Exit Sub

ErMsg:
    MsgBox "Please do not place the cursor between two slides"

End Sub