用于为页面上的所有形状提供公共边框的宏

  • 本文关键字:边框 用于 macros coreldraw
  • 更新时间 :
  • 英文 :


我使用的是CorelDraw X7。我有一个包含许多形状的页面,我希望构建一个宏来更改它,使得所有形状的边界矩形(包含所有形状的最小矩形(将具有给定大小的公共边界。我可以找到边界矩形的大小,并尝试使用ActiveSelection.AlignAndDistribute子移动形状,但这个子有很多参数,我不理解("帮助"对我没有帮助(。

我的想法是:

  1. 指定边界,比如pgBorder
  2. 获取边界矩形的宽度和高度,例如shpsWidth和shpsHeight
  3. 移动形状,使新边界矩形的左下角具有坐标(pgBorder,pgBorder(
  4. 将页面大小重置为shpsWidth+2*pgBorder resp。shps高度+2*pg边框

形状边界矩形现在应该用大小为pgBorder的边框包围。

这就是我目前所拥有的:

Sub GivePageCommonBorder()
Dim pgBorder As Double, shpsWidth As Double, shpsHeight As Double
Dim doc As Document
Dim pg As Page

Set doc = ActiveDocument
doc.Unit = cdrMillimeter
pgBorder = 20
Set pg = doc.ActivePage
' Select all shapes on the page
pg.Shapes.All.CreateSelection
shpsWidth = ActiveSelection.SizeWidth
shpsHeight = ActiveSelection.SizeHeight

' This is what I am lacking:
' Move the selection so its lower left corner has coordinates (pgBorder,pgBorder)

' Adjust page size
pg.SizeWidth = shpsWidth + 2 * pgBorder
pg.SizeHeight = shpsHeight + 2 * pgBorder
End Sub

致以最良好的祝愿Holger

我刚刚偶然发现了.Move方法,并构造了以下解决方案:

Sub GivePageCommonBorder()
Dim pgBorder As Double
Dim doc As Document
Dim pg As Page

Set doc = ActiveDocument
doc.Unit = cdrMillimeter
pgBorder = 5
Set pg = doc.ActivePage
pg.Shapes.All.CreateSelection
With ActiveSelection
pg.SizeWidth = .SizeWidth + 2 * pgBorder
pg.SizeHeight = .SizeHeight + 2 * pgBorder
.Move pgBorder - .LeftX, pgBorder - .BottomY
End With
End Sub

Holger

最新更新