英文:
VBA Visio aligning object to the middle
问题
I have problems with assigning the 2 or more vision objects to the middle.
My chart looks like this
and I want to have all of them aligned in one line.
The code I have looks as follows:
Dim VPage As Page
Set VPage = ActiveDocument.Pages("SLD")
Dim Vshp As Visio.Shape
Dim sel As Visio.Selection
Set sel = ActiveWindow.Selection
For Each Vshp In VPage.Shapes
If Vshp.Name Like "*UG*" Then
sel.Select Vshp, visSelect
sel.Selection.Align visHorzAlignNone, visVertAlignMiddle, False
End If
Next
At the following line:
sel.Selection.Align visHorzAlignNone, visVertAlignMiddle, False
The error: Object doesn't support this property or method is displayed
I am wondering what is wrong here, as I've picked up these codes from recorded macro and it was working there.
英文:
I have problems with assigning the 2 or more vision objects to the middle.
My chart looks like this
and I want to have all of them aligned in one line.
The code I have looks as follows:
Dim VPage As Page
Set VPage = ActiveDocument.Pages("SLD")
Dim Vshp As Visio.Shape
Dim sel As Visio.Selection
Set sel = ActiveWindow.Selection
For Each Vshp In VPage.Shapes
If Vshp.Name Like "*UG*" Then
sel.Select Vshp, visSelect
sel.Selection.Align visHorzAlignNone, visVertAlignMiddle, False
End If
Next
At the following line:
sel.Selection.Align visHorzAlignNone, visVertAlignMiddle, False
The error: Object doesn't support this property or method is displayed
I am wondering what is wring here, as I've picked up these codes from recorded macro and it was working there.
答案1
得分: 1
I'll provide the translation for the code part as requested:
请修改 Align 方法的代码为 sel.Align visHorzAlignNone, visVertAlignMiddle, False
。
You can also put this line outside the loop to align all shapes once
你还可以将这行代码放在循环之外,以一次性对所有形状进行对齐
Dim Vshp As Visio.Shape
Dim sel As Visio.Selection
Set sel = ActiveWindow.Selection
For Each Vshp In VPage.Shapes
If Vshp.Name Like "*UG*" Then
sel.Select Vshp, visSelect
End If
Next
sel.Align visHorzAlignNone, visVertAlignMiddle, False
这样可以对所有形状进行一次性对齐。
英文:
If you look at the help documentation for the Selection.Align method, you will see the following words
> Aligns two or more selected shapes.
For first selected shape this method can get error!
I don't understand what you want to do ?
Iterate all the connectors and align them vertically in the middle?
In this case, all connectors vertically (except the first of the selected ones) can change their position. Unless they are glued to the connection points on the green squares.
If they are glued, they won't move anywhere. In other words, nothing will happen.
Please modify code of Align method to sel.Align visHorzAlignNone, visVertAlignMiddle, False
.
You can also put this line outside the loop to align all shapes once
Dim Vshp As Visio.Shape
Dim sel As Visio.Selection
Set sel = ActiveWindow.Selection
For Each Vshp In VPage.Shapes
If Vshp.Name Like "*UG*" Then
sel.Select Vshp, visSelect
End If
Next
sel.Align visHorzAlignNone, visVertAlignMiddle, False
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论