|
本帖最后由 star81 于 2016-3-20 19:35 编辑
我的文档只有一页,但要打印多份,每一份打印要变其中的一个序号(递增),我在网上找了一个宏代码,但没有成功,输入起始页码时不能用。代码如下,请大神帮忙一下;
Sub PrintCopies()
'
' Macro1 Macro
'
'
Dim i As Long
Dim lngStart
Dim lngCount
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
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
If i < 10 Then
Selection.TypeText Text:="000" & i&
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
End If
If (i >= 10) And (i < 100) Then
Selection.TypeText Text:="00" & i&
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
End If
If (i >= 100) And (i < 1000) Then
Selection.TypeText Text:="0" & i&
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
End If
If (i >= 1000) And (i < 10000) Then
Selection.TypeText Text:=i
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
End If
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Selection.TypeBackspace
Next
End Sub
附件为需要打印的文档,要在“卷号”的位置打印序号,这个是要打印在产品标签上的,不同产品序号也不一样,所以想说可以用宏每次打印的时候可以根据需要打印份数以及设置开始序号
。
|
|