Word自动打印序列号
来源:网络收集 点击: 时间:2024-08-06复制以下代码;
2/9Sub autoSN()
Dim posX As Double
Dim posY As Double
Dim leftWord As String
Dim rightWord As String
Dim startNumber As String
Dim count As Integer
Dim s1 As Shape
posX = Selection.Information(wdHorizontalPositionRelativeToPage)
posY = Selection.Information(wdVerticalPositionRelativeToPage)
leftWord = abc 序列号前缀
startNumber = 100000
rightWord = 序列号后缀
count = 1 序列号的个数
For i = 1 To count
Set s1 = ActiveDocument.Shapes.AddTextbox(msoTextOrientationHorizontal, posX, posY, Selection.Font.Size * 8, Selection.Font.Size * 1.5)
s1.TextFrame.TextRange.Font.Size = Selection.Font.Size
s1.TextFrame.TextRange.Font.Name = Selection.Font.Name
s1.Line.ForeColor.TintAndShade = 1
s1.TextFrame.MarginBottom = 0
s1.TextFrame.MarginTop = 0
s1.ZOrder (msoSendBehindText)
s1.TextFrame.TextRange.Text = leftWord startNumber + i - 1 rightWord
ActiveDocument.PrintOut 打印前先在word内进行打印设置,如打印机,页数等
s1.Delete 打印后删除文本
Next i
End Sub
3/9打开需要打印的文件;
4/9按alt+f11呼出vba编辑界面;
5/9粘贴代码;
6/9返回word文档设置打印参数;
7/9光标停留在文档内需要打印序列号的位置;
8/9进入vba编辑窗口,按小箭头运行;
9/9可以修改的参数已经注释。
版权声明:
1、本文系转载,版权归原作者所有,旨在传递信息,不代表看本站的观点和立场。
2、本站仅提供信息发布平台,不承担相关法律责任。
3、若侵犯您的版权或隐私,请联系本站管理员删除。
4、文章链接:http://www.1haoku.cn/art_1074157.html