'MVCPPAGE.BAS

Function Main As String
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Move/copy a page                                                    '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim Form, APage, NewPage, Drawings, Temp, DObj As Object
Dim i, ai, InsertAfter, NPages As Integer
Dim Name, AName As String
Dim Move As Boolean

  Main = "Completed."
  With ActiveDocument
    NPages = .Count
    If NPages>=100 Then
      Main = "Sorry, your document is already full."
      Exit Function
    End If
    APage = .ActivePage
    AName = Apage.GetName
    ai = .Index(Apage)
    InsertAfter = ai

   'Display form
    Form = ReadForm("Mvcppage.frm")
    Form.SetIntValue("answer", NPages)
    If Form.ExecForm Then
      InsertAfter = Form.GetIntValue("answer")
      Move = (Form.GetStrValue("action") = "Move")
    else
      Main = "Cancelled"    
      Exit Function
    end if
    If InsertAfter > NPages Then
      Main = "There is no page N "+Str(InsertAfter)
      Exit Function
    End If

    'Insert blank and copy/move
    NewPage = .AddEmpty
    NPages = NPages + 1
    For i = NPages To InsertAfter + 2 Step -1
      Drawings = .Item(i - 1).Drawings
      Temp = Drawings.LoadOnto(.Item(i))
      If Temp <> NULL Then
         For Each DObj In Drawings
           Kill(DObj)
         Next DObj
      End If
      .Item(i).SetName(.Item(i - 1).GetName)
    Next i
    NewPage = .Item(InsertAfter + 1)
    If ai > InsertAfter Then APage = .Item(ai + 1)
    APage.Drawings.LoadOnto(NewPage)
    If AName <> "" Then NewPage.SetName(AName + " (copy)")
    .SetActivePage(NewPage)
    If Move Then Kill(Apage)
  End With

End Function
