2015-09-09 22 views
0

我有一個外部過程,它向Publisher頁面添加了很多形狀。可悲的是,一些形狀已放置在頁面之外。如何使用VBA在發佈器中獲取形狀,當它位於頁面外部時?

此形狀不在該頁面的Shapes集合中。任何人都知道我能從哪裏得到它們?

這裏說的複製問題示例代碼:

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 

我想是讓Shapes.Item(「佩佩」)的頁面是不是即使(左-150)。哪些形狀不在頁面中?

在此先感謝。

天使。

+0

可能重複的[通過Id或名稱獲取形狀](http://stackoverflow.com/questions/5527073/get-shape-by-id-or-name) –

回答

0

我找到了!

文檔中有一個ScratchArea,其中包含頁面中的所有形狀。

這樣我就可以像這樣修改代碼:

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 

謝謝!

相關問題