Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 08-05-2014, 12:51 PM
techmendz techmendz is offline New to Word VBA - Sequential Numbering Windows 7 32bit New to Word VBA - Sequential Numbering Office 2010 32bit
Novice
New to Word VBA - Sequential Numbering
 
Join Date: Jun 2014
Posts: 7
techmendz is on a distinguished road
Default New to Word VBA - Sequential Numbering

Hello all,

I am in the last step of the creation of my first VBA template. It basically needs to generate several pages with sequential numbering.



For example, I need to generate 50 pages and I need them to be numbered individually as 1 of 50, 2 of 50, 3 of 50, etc.

Thanks for the help in advance.
Reply With Quote
  #2  
Old 08-05-2014, 03:34 PM
macropod's Avatar
macropod macropod is offline New to Word VBA - Sequential Numbering Windows 7 32bit New to Word VBA - Sequential Numbering Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I can't see what this has to do with VBA. All you need do is design the template with the required PAGE and NUMPAGES fields in the page header or footer.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 08-05-2014, 09:38 PM
techmendz techmendz is offline New to Word VBA - Sequential Numbering Windows 7 32bit New to Word VBA - Sequential Numbering Office 2010 32bit
Novice
New to Word VBA - Sequential Numbering
 
Join Date: Jun 2014
Posts: 7
techmendz is on a distinguished road
Default VBA - Sequential Numbering

It has everything to do VBA since the template was created in VBA and I do not need the sequential numbering on the header or the footer.

In the form that I created I added a box that states Total of Boxes, you would input the total and the final product would give you the pages with the numbering as mentioned before.

I apologize if i didn't explain it correctly before.
Reply With Quote
  #4  
Old 08-05-2014, 10:03 PM
macropod's Avatar
macropod macropod is offline New to Word VBA - Sequential Numbering Windows 7 32bit New to Word VBA - Sequential Numbering Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

You are unlikely to be creating a template in VBA. You'll be far more likely to be creating a document from a template.

In any event, your initial post said you "need to generate 50 pages and I need them to be numbered individually as 1 of 50, 2 of 50, 3 of 50, etc." That's precisely what the PAGE and NUMPAGES fields are for. Although these fields should reside in the page header or footer, that doesn't mean they can't display somewhere else on the page. This can be done by putting them in a textbox in the header or footer, then dragging that textbox to wherever you want the numbers to appear. Any other content that needs to repeat on every page can likewise be inserted into the header or footer. All you then need is code to insert the required # of page breaks. For that, see, for example: https://www.msofficeforums.com/word-...html#post34477.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 08-06-2014, 05:18 AM
techmendz techmendz is offline New to Word VBA - Sequential Numbering Windows 7 32bit New to Word VBA - Sequential Numbering Office 2010 32bit
Novice
New to Word VBA - Sequential Numbering
 
Join Date: Jun 2014
Posts: 7
techmendz is on a distinguished road
Default Vba

Ok, here's the file so you can take a better look at it.

It's my first time creating something like this.

The idea that I have and maybe there is an easier way as you mentioned, on the field where it says No. of Total Boxes, as an example, the user would enter that she has a total of 50 boxes.

The result that I would like is when you hit Print, it should give you Page 1 of 50 on every page as I have mentioned above.
Attached Files
File Type: zip Work.zip (22.8 KB, 13 views)
Reply With Quote
  #6  
Old 08-06-2014, 05:55 AM
gmaxey gmaxey is online now New to Word VBA - Sequential Numbering Windows 7 32bit New to Word VBA - Sequential Numbering Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Code:
Private Sub cmdSubmit_Click()
Dim lngIndex As Long
Dim oRng As Word.Range
  With ActiveDocument
    .Bookmarks("NoOfBoxes").Range.Text = txtNoOfBoxes
    .Bookmarks("YearClosed").Range.Text = txtYearClosed
    .Bookmarks("CourtNumber").Range.Text = txtCourtNumber
    .Bookmarks("CaseName").Range.Text = txtCaseName
    .Sections.Add
    For lngIndex = 1 To txtNoOfBoxes
      Set oRng = ActiveDocument.Sections(2).Range
      oRng.Collapse wdCollapseEnd
      oRng.InsertBefore "Page " & lngIndex & " of " & txtNoOfBoxes
      oRng.Collapse wdCollapseEnd
      oRng.InsertBreak (wdPageBreak)
    Next lngIndex
  End With
  Unload Me
lbl_Exit:
  Exit Sub
End Sub
btw, as Paul suggested, you are not creating a template in VBA. Work.dotm is a template. You have created a rudimentary UserForm and with that Userform you are adding pages to the document created from Work.dotm
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #7  
Old 08-06-2014, 06:12 AM
techmendz techmendz is offline New to Word VBA - Sequential Numbering Windows 7 32bit New to Word VBA - Sequential Numbering Office 2010 32bit
Novice
New to Word VBA - Sequential Numbering
 
Join Date: Jun 2014
Posts: 7
techmendz is on a distinguished road
Default

Hi Greg,

Thanks for the help. Paul was correct indeed, sorry for the confusion, it's been a while since I've done any type of coding.

How do I make the document loop if I want to repeat the main page along with the sequential numbering?
Reply With Quote
  #8  
Old 08-06-2014, 07:14 PM
macropod's Avatar
macropod macropod is offline New to Word VBA - Sequential Numbering Windows 7 32bit New to Word VBA - Sequential Numbering Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

See attached, which implements the project via incorporation of the content into the page header/footer as previously described.

At present, there are two lines of code commented-out, so you can see what the code would send to the printer. Do note that on some systems the NUMPAGES field may not display correctly until you scroll down or refresh the display. That doesn't affect the printout, though.

With this approach, you don't even need to use a template - it would work just as well if you saved the dotm file as a docm or doc file.
Attached Files
File Type: zip Work.zip (24.2 KB, 20 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 08-07-2014, 05:40 AM
techmendz techmendz is offline New to Word VBA - Sequential Numbering Windows 7 32bit New to Word VBA - Sequential Numbering Office 2010 32bit
Novice
New to Word VBA - Sequential Numbering
 
Join Date: Jun 2014
Posts: 7
techmendz is on a distinguished road
Default

Paul,

That looks excellent, I will keep building from this on.

Many thanks are in order to everyone !!!
Reply With Quote
  #10  
Old 08-07-2014, 08:04 AM
techmendz techmendz is offline New to Word VBA - Sequential Numbering Windows 7 32bit New to Word VBA - Sequential Numbering Office 2010 32bit
Novice
New to Word VBA - Sequential Numbering
 
Join Date: Jun 2014
Posts: 7
techmendz is on a distinguished road
Default

Paul, one more thing, is there a way to remove the zeros and leave it as single digits? Turns out that they wont need that many digits.
Reply With Quote
  #11  
Old 08-07-2014, 08:12 AM
gmaxey gmaxey is online now New to Word VBA - Sequential Numbering Windows 7 32bit New to Word VBA - Sequential Numbering Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Open the template and select the Page field, right click and toggle the field code. Change the \### to \# or just delete it. Repeat with the NumPages Field.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #12  
Old 08-07-2014, 08:20 AM
techmendz techmendz is offline New to Word VBA - Sequential Numbering Windows 7 32bit New to Word VBA - Sequential Numbering Office 2010 32bit
Novice
New to Word VBA - Sequential Numbering
 
Join Date: Jun 2014
Posts: 7
techmendz is on a distinguished road
Default

Awesome, thanks Greg !!!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
New to Word VBA - Sequential Numbering How do I do a Sequential Numbering? gburya Word VBA 26 07-04-2017 03:29 PM
New to Word VBA - Sequential Numbering Sequential Document Numbering Geza59 Word VBA 18 01-15-2014 01:43 AM
New to Word VBA - Sequential Numbering Sequential page numbering im_rusahbh Word VBA 1 12-23-2013 05:28 PM
New to Word VBA - Sequential Numbering Sequential Numbering jdwoods Word VBA 7 12-16-2011 05:11 AM
New to Word VBA - Sequential Numbering Sequential Page Numbering of Multiple Word Docs bobmard Word 8 08-24-2011 08:51 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:52 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft