使用形状修复Excel VBA流程图

时间:2017-01-24 09:53:52

标签: excel-vba vba excel

我找到了一个名为n1ghthawk(2012!)的用户制作的旧解决方案,使用形状来形成可以按所选形状过滤的流程图。

正是我需要的,除了代码在某个带连接器的情况下失败。我自己没有解决这个问题,所以如果有人可以帮助我,我将不胜感激。

我会向受访者发送文件链接而不是发布代码,因为我认为这样可以更容易地提供帮助。在文件中,我设置了形状,以最简单的形式显示失败的场景。

1 个答案:

答案 0 :(得分:1)

感谢约翰帮忙。

我的一位同事刚刚指出了正确的方向,这3行停止了无限循环,让剧本在下一个形状上移动,修复了失败的情景:

For j = 1 To UBound(MyNames())
If thisshape.Name = MyNames(j) Then Exit Sub
Next

所以整个递归Sub现在看起来像这样:

Sub Get_LegUp(thisshape As Shape)

Dim con As Variant
Dim i As Long
Dim j As Integer
Dim dependentshape As Shape

'***
For j = 1 To UBound(MyNames())
    If thisshape.Name = MyNames(j) Then Exit Sub
Next
'***

namecount = namecount + 1
MyNames(namecount) = thisshape.Name

For i = 1 To shpconlist.Item(thisshape.Name).up.Count
    con = shpconlist.Item(thisshape.Name).up(i)

    namecount = namecount + 1
    MyNames(namecount) = con
    Set dependentshape = ActiveSheet.Shapes(con).ConnectorFormat.BeginConnectedShape

    Get_LegUp dependentshape

Next i
End Sub

如果有人想要代码重新创建功能,请回到这里,我会把它全部放在这里。

再次抱歉不遵守指南。