Consulting

Results 1 to 8 of 8

Thread: Dynamic page breaks depending on text position

  1. #1
    VBAX Newbie
    Joined
    Aug 2018
    Posts
    4
    Location

    Dynamic page breaks depending on text position

    So I have a Word 2013 document that I am adding a good amount of text to in the format of

    ----------
    *5-6 lines of assorted text
    ----------

    I am using the dashes as a simple deliminator to help differ between sections of text. For the best readability, I would like to have sections of text on one page and not break over pages. Something like

    'Find position of first ----------
    'Find position of next ----------
    If positionOfNext is on another page Then
         Insert page Break before first -----------
    End If
    Loop
    Is something like this possible to do? I have some experience with VBA in excel, but have never dabbled into VBA in word.

  2. #2
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,525
    Location
    If your '5-6 lines of assorted text' is all one paragraph, simply apply the 'keep together' paragraph attribute to it; otherwise apply the 'keep with next' paragraph attribute to all except the last paragraph. If you want to keep the first paragraph of ------ with the text that follows, apply the 'keep with next' paragraph attribute to that as well.

    Word will take care of the pagination automatically.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  3. #3
    VBAX Newbie
    Joined
    Aug 2018
    Posts
    4
    Location
    Quote Originally Posted by macropod View Post
    If your '5-6 lines of assorted text' is all one paragraph, simply apply the 'keep together' paragraph attribute to it; otherwise apply the 'keep with next' paragraph attribute to all except the last paragraph. If you want to keep the first paragraph of ------ with the text that follows, apply the 'keep with next' paragraph attribute to that as well.

    Word will take care of the pagination automatically.
    It is a few different lines of text because I have different styles applied to lines within it. I know of the keep together and keep with next, but when I have hundreds of these across a few documents, it would be tedious to apply these principles to each one. I want a way for word to automatically and dynamically apply the principles as more information gets added to the sheets.

  4. #4
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,525
    Location
    You can apply those attributes to the Styles concerned. That way, it's automatic.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  5. #5
    VBAX Newbie
    Joined
    Aug 2018
    Posts
    4
    Location
    Quote Originally Posted by macropod View Post
    You can apply those attributes to the Styles concerned. That way, it's automatic.
    This still does not help nor answer the original question.

    Most of the text, including the ---------- as deliminators are in the "normal" style while 1-2 lines within each comment block are in a "comment" style. I would have to manually go through and change all text to be in special styles to apply the keep with next, which is something tedious and not automatic and dynamic.

    My original question was asking if it is possible to parse through the document, find a "----------" block of characters, mark the vertical line that it is on, and then parse until the next one is found. Then depending on if the second is on another page or not, add a page break in. I am somewhat familiar with vba functions in Excel, but have never applied them, or this concept, to Word. I can search the libraries available to find the functions myself, I just didn't want to waste money at work searching for something that isn't possible.

  6. #6
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,525
    Location
    Well, you did say:
    I have different styles applied to lines within it.

    The solution is to use Word's Styles properly instead of trying to coerce the Normal Style to do whatever you fancy. Like it or not, that is the best way to answer to your question.

    The approach you've outlined is unreliable, since any edits after running the macro are liable to mess up the formatting. Moreover, what you're asking will increase the likelihood of document corruption.
    Cheers
    Paul Edstein
    [MS MVP - Word]

  7. #7
    VBAX Newbie
    Joined
    Aug 2018
    Posts
    4
    Location
    Quote Originally Posted by macropod View Post
    that is the best way to answer to your question.
    [/FONT][/COLOR][/LEFT]
    Its really not.

  8. #8
    Knowledge Base Approver VBAX Guru macropod's Avatar
    Joined
    Jul 2008
    Posts
    3,525
    Location
    Well, since you know so much, I'll leave it to your expertise...
    Cheers
    Paul Edstein
    [MS MVP - Word]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •