2020-01-15通过vba实现重复打印word文档并对其中表格动态编号

'''
Sub PrintCopies()

Dim i As Long
Dim lngStart
Dim lngCount
Dim rngDoc As Range

'提示需要打印多少份
lngCount = InputBox("Please enter the number of copies you want to print", "Please enter the number of copies you want to print", 1)

If lngCount = "" Then
    Exit Sub
End If

'提示本次打印从哪个号码开始打印,默认为1
lngStart = InputBox("Enter the starting number you want to print", "Enter the starting number you want to print", 1)
If lngStart = "" Then
    Exit Sub
End If

    
For i = lngStart To lngCount

    '编号的位置,依实际状况不同,需要修改Start和End的值
    'Set rngDoc = ActiveDocument.Range(Start:=22, End:=25)
    Set rngDoc = ActiveDocument.Tables(1).Cell(1, 1).Range
    
    '数字不满3位时前面补0
    If i < 10 Then
        rngDoc.Text = "00" & i
    End If
    
    If (i >= 10) And (i < 100) Then
        rngDoc.Text =  "0" & i
    End If
    
    If (i >= 100) And (i < 1000) Then
        rngDoc.Text =  i
    End If
    
    '调用打印
    Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
    wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
    ManualDuplexPrint:=False, Collate:=True, Background:=True, PrintToFile:= _
    False, PrintZoomColumn:=0, PrintZoomRow:=0, PrintZoomPaperWidth:=0, _
    PrintZoomPaperHeight:=0
    
    '未使用此方法,相当于在当前选择项上按Backspace键
    'Selection.TypeBackspace
Next

End Sub

'''

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容