-
Feb 15th, 2012, 12:23 PM
#1
Thread Starter
New Member
[WORD2007] Is this possible and if so how?
Hi I am just starting to use VBA in Word
PROBLEM: I have a load of tags like [p.345] but now I want to add a page in and increment the hard coded page numbers by 1.
I know how to input the number and presume I could get for loop to start at 2000 and presumably work backwards, but am unsure how to change data..
Is this possible and if so any sample code would be greatly appreciated
-
Feb 15th, 2012, 03:43 PM
#2
Re: [WORD2007] Is this possible and if so how?
are these page numbers? if so why are you not using pagenumber fields?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 15th, 2012, 03:58 PM
#3
Thread Starter
New Member
Re: [WORD2007] Is this possible and if so how?
Originally Posted by westconn1
are these page numbers?
YES
Originally Posted by westconn1
why are you not using pagenumber fields?
Because I dont know how to "Convert" them from [p.??] to what you said, the source document is utf-8 text with zero formatting, have a macro that does most of the formatting, so if theres an easy way please help if you are willing
-
Feb 15th, 2012, 04:22 PM
#4
Frenzied Member
Re: [WORD2007] Is this possible and if so how?
page numbering should be left to word!
nuff said!
here to grump!
-
Feb 15th, 2012, 10:26 PM
#5
Fanatic Member
Re: [WORD2007] Is this possible and if so how?
Hey don't be too hard on the guy. I used to have pages in large documents like this when I worked for insurance companies. Pages in these documents become their own entities and repagination would cause chaos. What we always did to add a page in those situations would be to add page 3A or something.
Word doesn't have a page object you can loop. What you could do is to loop through paragraphs and check for your page pattern... Forgive me I'm typing from memory and this is pseudocode.
Code:
Sub LoopParagraphs
Dim p as Paragraph
For each p in Activedocument.Paragraphs
If p.Range.Text Like "my pattern" Then
'Increment text in here
End If
Next
End Sub
Sorry I can't be more specific right now not enough time.
-
Feb 16th, 2012, 05:15 AM
#6
Re: [WORD2007] Is this possible and if so how?
as it is just text you could use a loop to replace each page number with +1
vb Code:
for i = lastpage to insrt step -1 ' record a macro to find "[p." & i & "]" and replace with "[p. & i + 1 & "]" next
where insrt is the page number position of the inserted page and lastpage speaks for itself
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Feb 19th, 2012, 12:19 PM
#7
Thread Starter
New Member
Re: [WORD2007] Is this possible and if so how?
Thanks all for the pointers..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|