TPE
![]() |
![]() |
![]() |
|
|
Tavvafi@gmail.com |
|||
≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡
Option Explicit
Sub SortMe()
Dim x As Long
Dim rayTitles() As Variant
Dim lIndex As Long
ReDim Preserve rayTitles(1 To ActivePresentation.Slides.Count) As Variant
' collect titles and indices in array
' Sort array only works with 1-dimension arrays so we'll combine the slide title and index
' then sort 'em out later:
For x = 1 To ActivePresentation.Slides.Count
rayTitles(x) = GetTitle(ActivePresentation.Slides(x)) & "|||" & CStr(x)
Next
' sort the array
Call BubbleSortVariantArray(rayTitles())
' rearrange:
For x = 1 To UBound(rayTitles)
' split out the index of the slide
lIndex = CLng(Mid$(rayTitles(x), InStr(rayTitles(x), "|||") + 3))
Debug.Print rayTitles(x)
ActivePresentation.Slides(lIndex).MoveTo ActivePresentation.Slides.Count
Next
End Sub
Function GetTitle(oSld As Slide) As String
' return the slide title for oSld if any
Dim oSh As Shape
For Each oSh In oSld.Shapes
If oSh.Type = msoPlaceholder Then
If oSh.PlaceholderFormat.Type = ppPlaceholderTitle Or oSh.PlaceholderFormat.Type = ppPlaceholderCenterTitle Then
' it's a title
GetTitle = oSh.TextFrame.TextRange.Text
End If
End If
Next
End Function
Public Sub BubbleSortVariantArray(rayIn() As Variant)
Dim lLow As Long
Dim lHigh As Long
Dim intX As Long
Dim intY As Long
Dim varTmp As Variant
On Error GoTo Errorhandler
' Get the bounds of the array
lLow = LBound(rayIn)
lHigh = UBound(rayIn)
For intX = lLow To lHigh - 1
For intY = intX + 1 To lHigh
If rayIn(intX) > rayIn(intY) Then
varTmp = rayIn(intX)
rayIn(intX) = rayIn(intY)
rayIn(intY) = varTmp
End If
Next intY
Next intX
NormalExit:
Exit Sub
Errorhandler:
MsgBox "There was a problem sorting the array"
Resume NormalExit
End Sub



































