我有一个循环,可以在visio绘图上自动生成矩形,但是我需要有脚本来自动排列矩形,因为我在手动在标题框下重新排列矩形的同时记录了一个宏。但是我的矩形数不断变化,因为if语句的结果不断变化,因为我的数据不断变化。我需要循环才能开始在标题框下的六个或七个矩形列中绘制它们。
For I = 1 To WS_Count
Set vsoShape =
Application.ActiveWindow.Page.Drop(Application.DefaultRectangleDataObject,
aoffset, boffset)
vsoShape.Text = ActiveWorkbook.Worksheets(I).Name
aoffset = aoffset
boffset = boffset + 0.75
Dev_Count = Dev_Count + 1
ActiveDocument.DiagramServicesEnabled = DiagramServices
Next I
我需要能够设置一个开始位置,以开始将矩形拖放到标题矩形下方,从而每六到七个矩形创建一个新列。谢谢
答案 0 :(得分:0)
每次I
被水平分割的形状数都可整除时的aOffset增量...
您可以使用Mod Operator If (iterator Mod runEveryXIterations = 0) Then ...
下面的示例应该阐明这个想法,代码并不完全是您所需要的,但是您应该能够理解这个想法:
Option Explicit
Public Sub printXY()
xyDistribute 10, 3, 0, 0, 0.75, 1.5
End Sub
Private Function xyDistribute(ByRef iterations As Long, _
ByRef newColAfter As Long, _
ByRef xPosInitial As Double, _
ByRef yPosInitial As Double, _
ByRef xStep As Double, _
ByRef yStep As Double)
Dim iter As Long
Dim xPos As Double
Dim yPos As Double
yPos = yPosInitial
xPos = xPosInitial
Debug.Print "xPos", "yPos"
For iter = 1 To iterations
Debug.Print xPos, yPos
' your code goes here
If (iter Mod newColAfter = 0) Then
yPos = yPos + yStep
xPos = xPosInitial
Else
xPos = xPos + xStep
End If
Next iter
End Function