首页 > 解决方案 > 使用 VBA 在 Powerpoint 中按字母顺序对部分进行排序

问题描述

我有一个包含许多部分的大 PowerPoint 文件,并且我不断添加一些部分。

我正在寻找一种按字母顺序对我的部分进行排序的方法。

我确信使用 VBA 是可行的,但我的知识有限,我找不到类似的代码来适应。

非常感谢你的帮助!

标签: vbasortingpowerpointsections

解决方案


这是基于经典的数组排序逻辑 - 但适用于部分。

如果您有很多部分,不知道这是否是性能问题。

Sub sortSections()

Dim sp As SectionProperties
Set sp = ActivePresentation.SectionProperties

Dim cntSections As Long
cntSections = sp.Count

Dim i As Long, j As Long
For i = 1 To cntSections - 1
    For j = i + 1 To cntSections
        If UCase(sp.Name(i)) > UCase(sp.Name(j)) Then
            sp.Move j, i
        End If
    Next
Next

End Sub

推荐阅读