Word: Automatically create TOC

grecko

New Member
Joined
Aug 12, 2006
Messages
13
Hey Guys,

I have to do newsruns on various companies which involves copying and pasting articles from Factiva into word. After deleting erroneous pieces of data from the heading (looks as below),i thought it would be a nice touch to add a TOC.

i question whether it is possible to have a macro automatically create a TOC from the titles ie 'Microsoft's Gates Looks to Energy', would be the first, without having to go through each article and tag them.

I was thinking one could pull bolded sentences, since i always bold the first sentance. Line space breaks wouldnt work obviously as large articles have more than one paragraph, unless i made two spaces intentionally between each article. Also, given there are say 8 sentances of corporate rubish at the top (stating this is a memo etc), there would have to be code to insert at a certain point. Any one have any ideas?

Microsoft's Gates Looks to Energy
4 November 2006
The Washington Post

Investing billions of dollars for Bill Gates without attracting a lot of attention is a bit like tiptoeing an elephant through a crowded office, but Cascade Investments LLC has managed to go little noticed in recent years while channeling investments for the Microsoft Corp. chairman.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Word does this for free, as long as you use styles.

For example, place your cursor in a line and press CTRL+ALT+1. You now have a Heading1. Similar for Heading2 and Heading3.

Then, Insert > Table should give you the option to insert a TOC.
The outline will be generated automatically from Heading1...Heading3, and you will get page numbers as well.

Does that help?

Denis
 
Upvote 0
Thanks for your reply, but no, not quite. I apologise if i did not make myself clear, but i would like to do so without having to tag each article, or as you put 'header'. I was wondering if there was a way to pull the every bolded statement and make a TOC, or could one make all bolded statements H1, then manually make the TOC?
thanks,
 
Upvote 0
You could try this:
Press Alt+F11 to go into the code environment, right-click and Insert > Module, and paste this code.
Code:
Sub MakeHeading1()
    Dim Par As Paragraph
    Dim i As Integer, iPars As Integer
    
    iPars = ActiveDocument.Paragraphs.Count
    For i = 1 To iPars
        If ActiveDocument.Paragraphs(i).Range.Font.Bold = True Then
            ActiveDocument.Paragraphs(i).Style = ActiveDocument.Styles("Heading 1")
        End If
    Next i
End Sub
To run, press Alt+F8 and double-click the macro name. All bold paragraphs will be Heading1. You can then create the TOC manually.

Denis
 
Upvote 0

Forum statistics

Threads
1,225,136
Messages
6,183,067
Members
453,147
Latest member
Lacey D

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top