#1
|
|||
|
|||
Sequential Numbering of Word Doc
I am trying to get a document to print with sequential numbers, but I am having no luck. At the moment I am manually entering the number after printing, I want to able to do this before the document prints, ideally remembering the last number printed as well. I have tried some of the suggestions in other posts but nothing is working the way its supposed to. Any help would be greatly appreciated. |
#2
|
||||
|
||||
Since you haven't told us what those posts are or how they are not working the way you want, it's pretty difficult to know how to meet your needs.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Hello Macropod, I have used the Macro from https://www.msofficeforums.com/word-...numbering.html you provided previously;
Code:
Sub CertificatePrint() Dim iStart As Integer, iEnd As Integer, i As Integer, StrArry On Error GoTo ErrHandler iStart = CInt(InputBox("What is the first Certificate to print?", "Print Certificates From", "1")) iEnd = CInt(InputBox("What is the last Certificate to print?", "Print Certificates To", iStart + 1)) If iStart = 0 Or iStart > iEnd Then Exit Sub With ActiveDocument For i = iStart To iEnd Step 2 With .Shapes(2).TextFrame.TextRange.Fields(2) StrArry = Split(.Code.Text, " ") .Code.Text = Replace(.Code.Text, StrArry(UBound(StrArry)), i) .Update End With With .Shapes(2).TextFrame.TextRange.Fields(2) StrArry = Split(.Code.Text, " ") .Code.Text = Replace(.Code.Text, StrArry(UBound(StrArry)), i + 1) .Update End With .PrintOut Next End With ErrHandler: End Sub I manage to get as far as the dialogue box asking me the first & last numbers to print, but the number does not populate in the text box I want it to, or any other for that matter. Also, once the range has been selected it does not send the document to the printer. |
#4
|
||||
|
||||
Your code is different from that in the thread from which you sourced it.
Your implementation of the code attempts to look in the second textbox in the document and update the second field in that textbox. I suspect nothing is being sent to the printer because the code fails before it gets that far - if for no other reason than because your document lacks a second field in the second textbox.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
The text box I am trying to populate is Text box 2 (I found this on the selection pane) I have just tried to change the Field source for the text by first changing the number to '3' after the text 'JHA #" with no luck, I then removed the text altogether and changed the number to '1' & '0' with no luck either. I'm not sure if you can tell, but I am totally new to this and have just been butchering my way through this trying to work out how they work. Appreciate the help Macro.
|
#6
|
||||
|
||||
Without actually seeing the problem document, it can be difficult for anyone to diagnose the issue. Can you attach a document to a post with some representative data (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
|
#8
|
||||
|
||||
There appears to be only one textbox in your document for the number output, and it lacks the required field. Its index # is 57.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
Now I'm completely confused. How do I change it to the Text box on the first page, the one sitting under the title section? Can I put it in the header section under the Breight logo?
|
#10
|
||||
|
||||
The textbox you refer to has the index #57 - presumably because it's the 57th shape object you've inserted into the document body. Hence, you'd refer to it as .Shapes(57).
And, yes, you could put it in the header, but then you'd refer to it by its header shape index #. If you're going to do that, you might put some text in the textbox like: "Copy #: " (without the quotes) and use the following version of the macro: Code:
Sub JHA_Print() Dim iStart As Long, iEnd As Long, i As Long On Error GoTo ErrHandler iStart = CInt(InputBox("What is the first Certificate to print?", "Print Certificates From", "1")) iEnd = CInt(InputBox("What is the last Certificate to print?", "Print Certificates To", iStart + 1)) If iStart = 0 Or iStart > iEnd Then Exit Sub With ActiveDocument For i = iStart To iEnd With .Sections.First.Headers(wdHeaderFooterPrimary) .Shapes(.Shapes.Count).TextFrame.TextRange.Words.Last.Text = i End With .PrintOut Next End With ErrHandler: End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#11
|
|||
|
|||
How did you find the index for the text box?
I am looking in the selection pane and i cant see text box #57. |
#12
|
||||
|
||||
By testing shape index #s with a loop in VBA.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#13
|
|||
|
|||
Do you have it working on your end?
|
#14
|
||||
|
||||
Of course!
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#15
|
|||
|
|||
I have put the new code in, drawn a new text box in the header section and still no joy.
What am I missing? (apart from my brain) Last edited by macropod; 04-21-2021 at 07:47 PM. |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Sequential numbering in Word - Unique numbers for table rows | krips | Word | 1 | 03-21-2018 05:06 AM |
Sequential numbering within Word | Earthly Way | Word VBA | 1 | 12-02-2015 07:36 PM |
New to Word VBA - Sequential Numbering | techmendz | Word VBA | 11 | 08-07-2014 08:20 AM |
Sequential Numbering | jdwoods | Word VBA | 7 | 12-16-2011 05:11 AM |
Sequential Page Numbering of Multiple Word Docs | bobmard | Word | 8 | 08-24-2011 08:51 AM |