MsOf07 [WORD2007] Is this possible and if so how?-VBForums
Results 1 to 7 of 7

Thread: [WORD2007] Is this possible and if so how?

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    3

    [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

  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    19,995

    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

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    3

    Re: [WORD2007] Is this possible and if so how?

    Quote Originally Posted by westconn1 View Post
    are these page numbers?
    YES

    Quote Originally Posted by westconn1 View Post
    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

  4. #4
    Frenzied Member
    Join Date
    Nov 2010
    Posts
    1,197

    Re: [WORD2007] Is this possible and if so how?

    page numbering should be left to word!

    nuff said!

    here to grump!

  5. #5
    Fanatic Member dmaruca's Avatar
    Join Date
    May 2006
    Location
    Jacksonville, FL
    Posts
    542

    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.

  6. #6
    PowerPoster
    Join Date
    Dec 2004
    Posts
    19,995

    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:
    1. for i = lastpage to insrt step -1
    2.    ' record a macro to find "[p." & i & "]" and replace with "[p. & i + 1 & "]"
    3. 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

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    3

    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.