VBA Visio aligning object to the middle

huangapple go评论57阅读模式
英文:

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

VBA Visio aligning object to the middle

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

VBA Visio aligning object to the middle

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.
VBA Visio aligning object to the middle

If they are glued, they won't move anywhere. In other words, nothing will happen.
VBA Visio aligning object to the middle


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

huangapple
  • 本文由 发表于 2023年4月6日 21:28:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/75950109.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定