View Single Post
  #6  
Old 07-03-2007, 10:57
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

I would try to rely less on the current state of the application. Meaning, less use of "activepage", "activelayer" and so on.

Also, when you duplicate the objects, you are actually moving the original objects and leave the duplicates on the current page.

Compare your code:

Code:
Set sr = ActiveSelectionRange
Set p = ActiveDocument.InsertPages(1, False, ActivePage.Index)
    
For Each s In sr
    s.Layer.Activate
    s.Duplicate
    s.MoveToLayer ActiveDocument.Pages(ActivePage.Index + 1).ActiveLayer
Next s
    
ActiveDocument.Pages(ActivePage.Index + 1).Activate
To something like this:

Code:
Dim PageNext As Page
Dim sDuplicate As Shape

Set sr = ActiveSelectionRange
Set PageNext = ActiveDocument.InsertPages(1, False, ActivePage.Index)

For Each s In sr
    Set sDuplicate = s.Duplicate
    sDuplicate.MoveToLayer PageNext.Layers(s.Layer.Name)
Next s
Since I never activated the current layer a shape is on, there is no need to restore the newly added page as the current one. Anyway, you can see that the new version is much more simplified and it doesn't rely on anything being "active" or "current"
Reply With Quote