View Single Post
 
Old 10-23-2019, 12:19 PM
craznbran craznbran is offline Windows 10 Office 2010
Novice
 
Join Date: Sep 2019
Posts: 2
craznbran is on a distinguished road
Cool Employ a single document in Word that will automatically insert sequential numbers in desired area

I have tried everything. Forum after forum after video after dummy self help and I cannot seem to figure it out. I need to be able to print a single document x30 at a time where my PO# 1XXXX will automatically update sequentially. I have also read several forums on this website & I cannot seem to get my dang document to do what I need it to do. I have added a macro to my document, I have "ran" it... and nothing. I've even looked up Dummies guide to VBA & macros and I cannot seem to understand what it is that I am doing wrong...

My template is already made out & I have the following Macro tied/saved to my document. My guess is, that in the macro, I am not telling it correctly where to pull the number from to start the 1st sequential order. Once I can figure it out, I will be using this document as a base template & will need to copy/save as new for other PO# types for various suppliers we use. So as user friendly as possible so that others on my team can update the PO# & print as well. I am on the most updated version of Microsoft Word for Office 365 MSO 64-bit. Please save me from insanity
Code:
Option Explicit

Sub CertificatePrint()
Dim iStart As Integer, iEnd As Integer, i As Integer
On Error GoTo ErrHandler
With ActiveDocument.Shapes(1).TextFrame.TextRange.Fields(1)
  iStart = CInt(InputBox("What is the first Certificate to print?", _
      "Print Certificates From", Split(Split(.Code.Text, " ")(0), "=")(1)))
  iEnd = CInt(InputBox("What is the last Certificate to print?", _
      "Print Certificates To", iStart))
  If iStart = 0 Or iStart > iEnd Then Exit Sub
  For i = iStart To iEnd
    If i = iStart Then
      With Application.Dialogs(wdDialogFilePrint)
        If .Show = 0 Then Exit Sub
      End With
    End If
    .Code.Text = "=" & i & " \# 0"
    .Update
    ActiveDocument.PrintOut
  Next
End With
ErrHandler:
End Sub

Last edited by macropod; 10-23-2019 at 09:58 PM. Reason: Added code tags
Reply With Quote