I wanted to duplicate my active page in quantity to the first page. I used the code but it brings error "Object does not support this property or method"
Sub DuplicateToFirstPage()Dim sr As ShapeRange, nc As Integer, pnext As Page, sduplicate As Shapenc = InputBox("enter required")For i = 1 To ncSet sr = ActivePage.Shapes.AllSet pnext = ActiveDocument.InsertPages(1, False, ActiveDocument.Pages(1))For Each s In sr.ReverseRangeSet sduplicate = s.Duplicatesduplicate.MoveToLayer pnext.Layers(s.Layer.Name)Next sNext ipnext.Activate
End Sub
Another challenge is that, if there are no shapes in page "p" it should display the message box but it still went ahead to duplicate empty page
If ActiveDocument.Pages(p).Shapes.Count = 0 ThenMsgBox "No objects found on the selected page to duplicate"End If
Place Exit Sub after MsgBox
you mean like this?
If ActiveDocument.Pages(p).Shapes.Count = 0 ThenMsgBox "No objects found on the selected page to duplicate": Exit SubEnd If
yes. To halt execution of your sub
I've done it. It stopped the sub whether there is a shape or not
yinkajewole said:It stopped the sub whether there is a shape or not
You having check whether exist shapes on the page or not
If ActiveDocument.Pages(p).Shapes.Count = 0 Then
MsgBox "No objects found on the selected page to duplicate"
Exit Sub
else
MsgBox "Work on"
End If
It still duplicated an empty page
do you want duplicate current page?
Then change to:
If ActivePage.Shapes.Count = 0 Then
not really.
I am using a userform that I will enter the page I want for duplication. i.e. I may be on page 9, then I just invoke the userform to duplicate page 14. So, if there is no shape on page 14, it should give me a message box that there is nothing. and if there is shape found there, it should go ahead to duplicate
well. Then write:
Else
' Shapes found.
For i = 1 To NumberOfDuplicatedPages
' whole code to duplicate pages and shapes on it
......
Next i