macro help .. how to sort according to numbering of pages of document ?

i have 20 page document

all pages name is in form of numbers like1,20,7,8,4,5,6,10,15,18,13,2,9,3,11,14,12,16,17,19 etc.

now i want to sort all pages in proper sequence of numbering like 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 etc.

Parents
No Data
Reply
  • Works for numbers too.

    Sub AlphbetizePages()
    Dim p As Page, doc As Document, i As Integer, x As Integer, j As Integer
    Dim pageArray() As String, pageName As String, pa As Long

    Set doc = Application.ActiveDocument
    pa = doc.Pages.Count - 1: i = 0
    ReDim pageArray(pa)

    For Each p In doc.Pages
    pageArray(i) = p.Name
    i = i + 1
    Next p

    With ActiveDocument.Pages
    For x = 1 To .Count - 1
    For j = x + 1 To .Count
    If UCase(.Item(x).Name) > UCase(.Item(j).Name) Then
    .Item(x).MoveTo j
    .Item(j - 1).MoveTo x
    End If
    Next j
    Next x
    End With
    End Sub
Children