0

i've a external process which adds a lot of shapes to a Publisher page. Sadly some of the shapes have been placed outside of the page.

This shapes are not in the Shapes collection of that page. Anybody know where can I get them?

Here a sample code that replicate the problem:

Sub main()
    Dim oPage As Page
    Dim oTable As Table
    Dim oBox As Shape
    Dim oLine As Shape


    Set oPage = ActiveDocument.Pages(1)
    Set oBox = oPage.Shapes.AddTable(2, 1, -150, 50, 120, 30, False)
    oBox.Name = "Pepe"

    Set oBox = oPage.Shapes.AddTable(2, 1, 350, 150, 120, 30, False)
    oBox.Name = "Pepa"

    Set oLine = oPage.Shapes.AddConnector(msoConnectorElbow, 0, 0, 100, 100)

    With oLine.ConnectorFormat
        .BeginConnect oPage.Shapes.Item("Pepe"), 1 'here are the error!!!
        .EndConnect oPage.Shapes.Item("Pepa"), 1
    End With

End Sub

What I want is to get the Shapes.Item("Pepe") even when is not in the page (Left -150). Where are the shapes that are not in the page?

Thanks in advance.

Angel.

  • possible duplicate of [Get shape by Id or Name](http://stackoverflow.com/questions/5527073/get-shape-by-id-or-name) – Tom K. Sep 09 '15 at 15:14

1 Answers1

0

I've found it!!

There are a ScratchArea under Document with all the shapes out of the pages.

So I can modify the code with something like this:

Sub main()
    Dim oPage As Page
    Dim oTable As Table
    Dim oBox As Shape
    Dim oLine As Shape
    Dim oScratch As ScratchArea


    Set oPage = ActiveDocument.Pages(1)
    Set oScratch = ActiveDocument.ScratchArea
    Set oBox = oPage.Shapes.AddTable(2, 1, -150, 50, 120, 30, False)
    oBox.Name = "Pepe"
    oBox.Tags.Add "Cuadro", "Pepe"

    Set oBox = oPage.Shapes.AddTable(2, 1, 350, 150, 120, 30, False)
    oBox.Name = "Pepa"
    oBox.Tags.Add "Cuadro", "Pepa"

    Set oLine = oPage.Shapes.AddConnector(msoConnectorElbow, 0, 0, 100, 100)

        With oLine.ConnectorFormat
            On Error Resume Next
            .BeginConnect oPage.Shapes.Item("Pepe"), 1
            If Err.Number <> 0 Then
                Err.Clear
                .BeginConnect oScratch.Shapes.Item("Pepe"), 1
            End If
            .EndConnect oPage.Shapes.Item("Pepa"), 1
            If Err.Number <> 0 Then
                Err.Clear
                .EndConnect oScratch.Shapes.Item("Pepa"), 1
            End If
            On Error GoTo 0
        End With

    End Sub

Thanks!!