coreldraw vba脚本教程-流水号生产-高级版
1、新建三个按钮控件分别命名为mubiaobtn,liushui,CommandButton1新建两个文本框用于输入范围分别命名为from,to;新建六个文本框用于变量的定义分别命名为qnum,qnum1,qnum2,hnum,hnum1,hnum2 ,其他控件请参照上次的增强版经验教程,布局及效果如下;

2、为模板指定也就是CommandButton1编写代码如下:
Dim q As Shape, muban As ShapeRange, num As Shape, num1 As Shape, num2 As Shape
Private Sub CommandButton1_Click()
Set muban = ActiveSelectionRange
On Error Resume Next
Set num = ActiveSelection.Shapes.FindShape("num")
Set num1 = ActiveSelection.Shapes("num1")
Set num2 = ActiveSelection.Shapes("num2")
End Sub

3、为流水指定也就是liushui编写代码如下:
Private Sub liushui_Click()
On Error Resume Next
ActiveDocument.Unit = cdrMillimeter
Dim s As Shape, p As ShapeRange, n As String, n1 As String, n2 As String, d As Integer
d = 1
For i = from.Text To too.Text
n = qnum.Text & i & hnum.Text
n1 = qnum1.Text & i & hnum1.Text
n2 = qnum2.Text & i & hnum2.Text
Set p = muban.Duplicate()
p.LeftX = p.LeftX + (p.SizeWidth + 10) * d
num.Text.Story.Text = n
num1.Text.Story.Text = n1
num2.Text.Story.Text = n2
d = d + 1
Next i
End Sub
Private Sub mubiaobtn_Click()
Set q = ActiveShape
End Sub

4、代码已经编写完成,效果如下 欢迎参考指正 cdrvba欢迎您
