Results 1 to 3 of 3
  1. #1

    Retrieving Chapter Numbers

    In a macro I am trying to write, I would like to be able to determine the chapter number for any paragraph that is selected (all chapters are marked with the Heading 1 - Heading 9 styles). Is there a simple way of doing this?

    "Selection.Information" seems to provide a wealth of information about the current selection, but not what chapter it is located in.



  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Silicon Valley, USA
    Thanked 94 Times in 90 Posts

    Re: Retrieving Chapter Numbers do you know what chapter a randomly selected paragraph is in? Do you scroll up to the immediately previous Heading1 and read it? That process could be implemented in VBA. VBA also might be able to determine the count of Heading1s above the insertion point, which might well be more reliable than trying to parse text (particularly if you didn't put the chapter number in the text).

    However, if you have the flexibility to make format changes to the document, making each chapter a new section would be the easiest way to handle this. Depending on why you need this information, there probably are other approaches as well.

  3. #3
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Sun Prairie, Wisconsin, Wisconsin, USA
    Thanked 128 Times in 123 Posts

    Re: Retrieving Chapter Numbers

    The StyleRef field can access the contents of the last paragraph using a style. I'm not sure how you would access this information using VBA. For more on fields you may want to check out the links at:
    (<A target="_blank" HREF=>

    You would want to have your chapter heading be one style, though.

    What is it that you are trying to accomplish with your macro? There may be other ways to accomplish your objective.
    Charles Kyle Kenyon
    Madison, Wisconsin

Posting Permissions

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