Why won't this code work?

Anyone have any idea why this code won't work?  It keeps throwing an error on lAy.delete.  It will work with some pages but not with others.  It's actually really irritating that I have to even delete layers because the stupid InsertPages function is copying layers from the active page.  Is there any way to stop the bloody InsertPages function from copying the active page layers??  >=(  Coding for this program is quite possibly the most frustrating thing I have ever done.  There is no way it should be this fing difficult!

    Dim p1 As Page
    Dim lAy As Layer
        
    'Creates a page after the active page.
    Set p1 = ActiveDocument.InsertPages(1, False, ActivePage.Index)
    Set p1 = ActivePage
        
    For Each lAy In p1.Layers
        lAy.Delete
    Next

  • Ok, I corrected some stuff in my Code and got it working. I think the problem was that you can't delete the "Guides" Layer so I wrote it as such:

    'Creates a page after the active page.
    Set p1 = ActiveDocument.InsertPages(1, False, ActivePage.Index)
    p1.Activate

    For Each lAy In p1.Layers
    If lAy.Name <> "Guides" Then
    MsgBox (lAy.Name)
    lAy.Delete
    End If
    Next

    The fact that the layers are being copied is still really strange. When you "Insert Page", "Insert Page After" or "Insert Page Before" from the Insert menu it does not copy the layers.