'CLNPAGE.BAS
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Clone a page                                                        '
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Function Main As String

Dim Form, apage,page,drawings As Object
Dim i,npages,nclones As Integer,ans,name As String

  With ActiveDocument
    npages = .Count
    If npages = 100 Then
      Main = "Cannot clone a page." + Chr(13) + Chr(13) + "Document cannot contain more than 100 pages."
      Exit Function
    End If
  
    'Display form
    Form = ReadForm("Clnpage.frm")
    Form.SetIntValue("CloneNumber", 1)  
    If Form.ExecForm Then
      nclones = Form.GetIntValue("CloneNumber")
    Else
      Main = "Cancelled"
      Exit Function
    End If
  
    If nclones + npages>100 Then
      Main = "Cannot clone a page." + Chr(13) + Chr(13) + "Document cannot contain more than 100 pages."
      Exit Function
    End If
  
    'Clone active page
    apage = .ActivePage
    drawings = apage.Drawings
    name = apage.GetName
    If name = "" Then
      name = "Page " + Str(.Index(apage))
    End If
    For i = 1 To nclones
      page = .AddEmpty
      drawings.LoadOnto(page)
      page.SetName(name + " (" + Str(i+1) + ")")
    Next i
    .SetActivePage(apage)
  End With
  Main = "Completed."

End Function
