Consulting

Results 1 to 3 of 3

Thread: Go to beginning and end of selected text

  1. #1
    VBAX Newbie
    Joined
    Jan 2023
    Posts
    5
    Location

    Go to beginning and end of selected text

    I want to be able to select text near the start of a paragraph (it will be the title of a publication - see steps 1 and 3 below), and change it from BodyText to Heading 5 format.
    The process would be, as I see it:
    Manually select the text
    With VBA:
    1. Go to the start of the selection
    2. Click Enter
    3. Go to the end of the selection
    4. Click Enter (this creates three paragraphs instead of one)
    5. Remove paragraph numbers from the two new paragraphs (2nd and 3rd)
    6. Format the middle paragraph as Heading 5
    7. With the Heading line still selected Click Alt + Ctrl + Enter (moves the third line to the end of the Heading line, where it was originally)
    8. Place the cursor in the first line
    9. Click Alt + Ctrl + Enter (moves the Heading and third line onto the first line, where it also was originally)
    10. Delete a space which will have been put in at the start of the Heading line.


    Example:

    Jack and Jill went up the hill to fetch a pale of water

    becomes:

    Jack and Jill
    went up the hill
    to fetch a pale of water

    becomes:

    Jack and Jill
    went up the hill
    to fetch a pale of water

    becomes:

    Jack and Jill went up the hill to fetch a pale of water


    The purpose is to get these titles to show up in the Navigation pane (among Heading 1 headings) as a quick reference list.
    Thanks for any help.
    Geoff

  2. #2
    VBAX Contributor
    Joined
    Jul 2020
    Location
    Sun Prairie
    Posts
    123
    Location
    Quote Originally Posted by GCWesq View Post
    ***
    Example:

    Jack and Jill went up the hill to fetch a pale of water

    becomes:

    Jack and Jill
    went up the hill
    to fetch a pale of water

    becomes:

    Jack and Jill
    went up the hill
    to fetch a pale of water

    becomes:

    Jack and Jill went up the hill to fetch a pale of water


    The purpose is to get these titles to show up in the Navigation pane (among Heading 1 headings) as a quick reference list.
    Thanks for any help.
    Geoff
    See Headings that do not show up in the Navigation Pane or in a Table of Contents (or in Cross-References / Hyperlinks).

    You need the entire Word paragraph to be in the style for it to show up in the Navigation Pane.

    I do not have the vba for it, but the method would be to put your selected text into a separate paragraphs, apply the Heading 5 style, then add a Style Separator between the each of the paragraphs. This makes it appear as a single paragraph in the printed document but the part set in Heading 5 style will show up in the Navigation Pane.

    Note from the linked article, you can get your text into a Table of Contents, without messing around like this. Would that serve? I can conceive of having a Table of Contents in a Frame or Textbox in the header so it is in the margin of the document.

  3. #3
    VBAX Newbie
    Joined
    Jan 2023
    Posts
    5
    Location
    Hi Chas.
    Thanks very much for the reply.
    I had actually been to that website, and several others. I have succeeded in getting my headings into the Navigation Pane and not in the ToC, which is what I want (see end of my previous post).
    As I have to do this regularly, I was hoping to get a macro to do it for me.
    But I ran into trouble at step 1, which was to put the cursor at the start of the selection.
    The Style Separator you suggest is activated by the Alt + Ctrl + Enter key strokes listed in my procedure description. So that's all good.

Posting Permissions

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