PDA

View Full Version : Go to beginning and end of selected text



GCWesq
01-27-2023, 12:03 AM
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:

Go to the start of the selection
Click Enter
Go to the end of the selection
Click Enter (this creates three paragraphs instead of one)
Remove paragraph numbers from the two new paragraphs (2nd and 3rd)
Format the middle paragraph as Heading 5
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)
Place the cursor in the first line
Click Alt + Ctrl + Enter (moves the Heading and third line onto the first line, where it also was originally)
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

Chas Kenyon
01-27-2023, 08:33 PM
***
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) (https://answers.microsoft.com/en-us/msoffice/forum/all/headings-that-do-not-show-up-in-the-navigation/1d3bdc6d-218b-4b90-8e58-f1e0530f75bd).

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 (https://www.addbalance.com/usersguide/styles.htm#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.

GCWesq
01-27-2023, 09:32 PM
Hi Chas.
Thanks very much for the reply. :content:
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.