![]() |
|
#5
|
|||
|
|||
|
Thanks all.
I think I wasn't clear about what I wanted to accomplish. So I'm going to try to better describe my goal. I do not want a TOC that uses the normal TOC Heading styles, because those all change the appearance of the text in the document. And I don't want the resultant "list" itself to have indented text lines. I believe I've figured out how to make each of these items appear in a plain list (including the desired hyperlinks) by inserting Field Codes (FC). However, because this document has 120 of these macro items spread out over 215 pages, I really need a macro to help me locate and mark them all. Here's what almost worked: I knew how to find each item (all begin with "Sub" followed by a space), so -- started at the top of the document -- I recorded a macro to find that string, then move (down) to the location of that macro's name, copy that name text, move 10 spaces to the right, then create the field code (pasting that copied name into it) and insert that field code at that location. After recording that macro, I confirmed the inserted field code for the first item was as I'd hoped, so I ran the macro. It found the second item and inserted a field code at the desired location, but not using the correct name text for that second item (it inserted the text from the first one). Nevertheless, I tested the general concept by returning again to the top of the document, then creating there a Custom TOC (being sure to checkmark "Table entry fields" under Options). The attached screenshot of the top of the 1st page of the document shows the resultant list. Other than the second item shows the wrong name, this is the sort of list I was looking for. But I don't know how to fix this recorded macro to do the copy/paste when/how I'd hoped. Here's that recorded macro: Sub tmp() ' ' tmp Macro ' ' Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "Sub " .Replacement.Text = "" .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False End With Selection.Find.Execute Selection.MoveDown Unit:=wdLine, Count:=1 Selection.HomeKey Unit:=wdLine Selection.MoveRight Unit:=wdCharacter, Count:=2 Selection.EndKey Unit:=wdLine, Extend:=wdExtend Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend Selection.Copy Selection.MoveRight Unit:=wdCharacter, Count:=1 Selection.TypeText Text:=" " Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _ "TC ""SectionSign Macro"" ", PreserveFormatting:=False End Sub I can see at the end that the name of the first item appears "hard coded". Obviously, I'd wanted it to insert into the FC code field the text I thought it had copied just above. How to do that? My other problem is that I don't know how to automate this macro so it will keep repeating itself in doing this "find and repeat action" process to similarly mark all of the remaining 118 macro items in this document. Can someone please tell me how to fix these issues? Thanks |
| Tags |
| list, macros, toc |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Preventing "Keep the last item you copied" popup on exit | gogreen | Word | 0 | 09-15-2019 03:48 PM |
| How to create a "Font color" button and a "Highlight text" button in the Quick Launch toolbar ? | gloub | Word | 12 | 02-19-2019 03:19 PM |
| Combine "sort within groups" and "identify duplicate/unique values" in two different variables. | civilcervant | Excel | 3 | 06-12-2017 07:27 AM |
How do I stop option for "new blog post" appearing when I create a new Word document?
|
Kimu | Word | 3 | 10-27-2014 02:58 AM |
| Word crashing on "sort" routine | Kayale | Word | 0 | 04-12-2010 04:54 PM |