我正在尝试使用GlueTo
在Visio中将形状粘贴到另一个这是代码
Set trgObj = Cell.shape.Document.Masters("Trigger").Shapes(1)
Dim x As shape
Set x = ActivePage.Drop(trgObj, flowConnector.CellsU("PinX"), flowConnector.CellsU("PinY"))
Dim vsoCell1 As Visio.Cell
Dim vsoCell2 As Visio.Cell
Set vsoCell1 = x.CellsU("PinX")
Set vsoCell2 = Application.ActiveWindow.Page.Shapes.ItemFromID(flowConnector.ID).CellsSRC(7, 1, 0)
vsoCell1.GlueTo vsoCell2
'The following code I obtained through running a macro in visio
'Dim vsoCell1 As Visio.Cell
'Dim vsoCell2 As Visio.Cell
'The following is the equivalent to x
'Set vsoCell1 = Application.ActiveWindow.Page.Shapes.ItemFromID(51).CellsU("PinX")
'The following is the equivalent to flowConnector
'Set vsoCell2 = Application.ActiveWindow.Page.Shapes.ItemFromID(12).CellsSRC(7, 1, 0)
'vsoCell1.GlueTo vsoCell2
它返回“此操作的不适当的目标对象”,但奇怪的是我正在使用的代码是通过录制宏获得的。我无法理解为什么代码在我将其记录在宏中时起作用,但是当我使用它时却没有。 如果有人能提供任何帮助,我将非常感激。
答案 0 :(得分:0)
我已经找到问题而不是使用宏
提供的代码Dim vsoCell1 As Visio.Cell
Dim vsoCell2 As Visio.Cell
Set vsoCell1 = x.CellsU("PinX")
Set vsoCell2 = Application.ActiveWindow.Page.Shapes.ItemFromID(flowConnector.ID).CellsSRC(7, 1, 0)
而是使用以下
Dim vsoCell1 As Visio.Cell
Dim vsoCell2 As Visio.Cell
Set vsoCell1 = Application.ActiveWindow.Page.Shapes.ItemFromID(x.ID).CellsSRC(visSectionConnectionPts, 0, 0)
Set vsoCell2 = Application.ActiveWindow.Page.Shapes.ItemFromID(flowConnector.ID).CellsSRC(visSectionConnectionPts, 1, 0)
,其中
visSectionConnectionPts, 0, 0)
0,0引用连接点或x单元格中的单元格
和
visSectionConnectionPts, 1, 0)
引用连接点中的单元格1或y单元格