#1
|
|||
|
|||
Auto generate X pages from input
Hi
I am trying to figure out a way to create X number of pages from a single input value in my Word document. Example: Input value 5 units of -> create 5 new Word pages. Has anybody experience with this matter? Best regards! |
#2
|
||||
|
||||
You are going to have to be clearer what it is that you want to achieve with regard to 'pages'. There are no 'pages' in a Word document. Word is not a page layout application. You could insert five page breaks (see macro), but what would be the point of that?
Code:
Sub Macro1() Dim i As Integer Dim strPages As String strPages = InputBox("How many pages?", , 5) If IsNumeric(strPages) = False Then Exit Sub If Not strPages = "" Then For i = 1 To Val(strPages) Selection.InsertBreak wdPageBreak Next i End If End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
What I am trying to achieve is a document layout where I can input a value of e.g. 5 on my first page, which then generates 5 new pages.
The 5 new pages are then created with title Unit 1, Unit 2, Unit 3, Unit 4, Unit 5 |
#4
|
||||
|
||||
I think this should be done with a combination of style and macro.
If you customised a style in your document to provide the 'Unit #' as an autonumber and include the "new page" setting then the macro could be as simple as Code:
Sub AddPages() Dim iNum As Integer iNum = Val(InputBox("How many units are you adding?", , 5)) If iNum > 0 Then Selection.Style = "Heading 1" Selection.TypeText String(iNum, vbCr) End If End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#5
|
||||
|
||||
See, for example:
https://www.msofficeforums.com/word-...html#post34477 https://www.msofficeforums.com/word-...html#post33829 https://www.msofficeforums.com/word-...tml#post113655
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#6
|
|||
|
|||
Thanks for the responses!
I have tried to configure it using both of your suggestions, however what I am missing is creating a interactive field on a line as illustrated on the attached document, where the user can input a desired value of units from where it autogenerates the new pages with the content of the starting page "Unit 1" but with new indices unit 2, unit 3 and etc. ? Is this possible? |
#7
|
||||
|
||||
The first link I posted shows how to do that where all pages have the same content except for the numbers.
The second link I posted shows how to do it for the purposes of generating printouts only. The third link I posted supplies a macro to do it for the purposes of generating PDFs only.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#8
|
|||
|
|||
Hi macropod
I have looked at the first post you refer to which have some similarities to what I am trying to achieve with my document (attached addpages.docm), however I still miss the link to create a functionality where I can click on the line in "No. of Units" from where it runs a macro asking "how many units?" and then generate the desired quantity of pages with the content from page 2 in the attached file. Finally it then writes the selected quantity on the line "No. of Units". Best regards |
#9
|
||||
|
||||
With the template in the first link, you don't type anything into the document - the macro takes care of all numbering. If you let that macro run and input some appropriate values, you will see that the document will automatically have the required number of pages with the number range specified.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#10
|
|||
|
|||
I know, but I dont want the macro to run as soon as I open the document. Have you looked at the document I have uploaded in the #6 thread of the posts called addpages.docm and understood what I want to achieve?
Example: If a person opens the document "addpages.docm" and clicks on the grey line "No. of Units" the macro runs and ask "how many units". The user then puts in 5, as an example, from where the macro creates 5 pages of the page "2" content in the document and updates the Unit numbering starting with Unit 1 and ending with 5. |
#11
|
||||
|
||||
Quote:
The nearest you'll get to what you've described is with something like the attached. The macro runs after you input the number into the formfield, then tab out of it. To get the numbering to update, it is necessary for that part, at least, to be in the page header.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#12
|
|||
|
|||
This works very well, thank you macropod!
One thing I noticed though was, when you enter a value for example 2 it generates the 2 pages properly, however if then the value was wrong and you want to change it to 4 the macro creates 2 x 4 pages instead of 4. Is this something that can be corrected? |
#13
|
||||
|
||||
Presumably, that's because you've already generated 2 pages before inputting the 4. The macro works by replicating the existing content. So, if you want to double the page count, simply re-input the 2; otherwise close the document & start over.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Auto-correct on existing text without input | m9rbid | Word | 1 | 12-18-2017 01:20 PM |
How to auto-generate whole Powerpoint presentations from a set of data? | olibot2000 | PowerPoint | 1 | 06-24-2017 09:01 PM |
Automatically generate formulas from just the row numbers (auto insert the column) | knewman | Excel | 14 | 04-25-2017 11:54 PM |
Crash after power failure. Doc is now blank and appears to auto-generate as a new doc on opening | Jbobjones | Word | 0 | 04-28-2015 09:37 PM |
Auto Generate Invoice Number Word 2013 | Jonah245 | Word VBA | 3 | 09-04-2014 05:24 PM |