前两天做上市会,打印试乘试驾保证书,想自动打印份数编号。不会 VBA,幸亏群里“江山”指点迷津,并亲自写出代码,特纪念在此

 1 Sub PRNTbyZSM()
 2 
 3 Dim fsbh As String  '份数编号
 4 Dim l As Integer
 5 Dim i As Integer
 6 Dim j As Integer
 7 
 8 Dim c As Integer
 9 
10 c = Val(InputBox("请输入总份数", "输入份数,默认10份", 10))
11 
12     Selection.TypeBackspace
13 
14         Windows("奔腾试乘试驾保证书").Activate
15         Selection.WholeStory
16         Selection.Copy
17         Documents.Add DocumentType:=wdNewBlankDocument
18         Selection.PasteAndFormat (wdPasteDefault)
19         ActiveWindow.ActivePane.VerticalPercentScrolled = 49
20  If MsgBox("即将打印" & c & "份,请再次确认!", vbQuestion + vbYesNo) = vbYes Then
21     For i = 1 To c
22         Selection.HomeKey Unit:=wdStory
23         Selection.EndKey Unit:=wdLine
24         fsbh = Format(i, "00000")
25         l = Len(fsbh)
26         Selection.TypeText Text:=fsbh
27         ActiveDocument.PrintOut
28         For j = 1 To l
29             Selection.TypeBackspace
30         Next j
31         DoEvents
32     Next i
33     MsgBox "打印文档已经发送到打印机!"
34     ActiveWindow.Close
35 End If
36 End Sub
View Code

相关文章:

  • 2021-10-25
  • 2022-12-23
  • 2021-12-15
  • 2021-07-18
  • 2021-12-14
  • 2021-12-20
  • 2021-07-24
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2021-09-20
  • 2021-08-27
  • 2021-10-07
  • 2022-12-23
相关资源
相似解决方案