Link to home
Start Free TrialLog in
Avatar of patrickab
patrickabFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Alphabetical list of paragraph headings with page numbers - generated by VBA

Good morning MS Word Experts,

I have a Word document of about 2100 lines long with over 400 paragraphs. It's essentially a long series of notes.

All I want is a macro-generated alphabetical list of all the paragraph headings and the page number on which I can find each item. The result needs to be in page 1 of the existing document. I also need to be able to run the macro as often as needed when I add new notes. I don't expect the macro to update the list, instead I would manually delete page 1 before running the macro.

I'm afraid I can't upload the file, however I can make all the paragraph headings one particular font and point size - for example, Tahoma - pt12

Patrick
SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Patrick (matthewspatrick) suggests building an set if indexes (indices?) but what you described can be done with a TOC if the paragraph headings use a heading style.

Have you tried using the inbuilt Table of Contents facility?
Avatar of patrickab

ASKER

Patrick,
Thank you for your contribution. Unfortunately I have a clue as to how to make use of it. I have copied your macro into an ordinary VBA Module and run it. It never seems to stop and I can't see what it has done - perhaps the results aren't visible - I just dunno.
The trouble is that in large part I use MSWord just as a simple word processor. I have absolutely no idea how to get it to create Tables of Contents or Indexes. In my original question (this is a virtual repeat) I was told to read up on those features - somewhat defeats the object of asking a question here!
So how do I start on this project, make use of your macro and conclude it with a list of paragraph headings and the page numbers on which they can be found?
Regards
Patrick
If you are using 2003 or earlier, do Insert/Reference, Index and tables... and choose the Index or Table of Contents tab.
Oops - should have been...
Patrick,
Thank you for your contribution. Unfortunately I haven't a clue as to how to make use of it. I have copied your macro into an ordinary VBA Module and run it. It never seems to stop and I can't see what it has done - perhaps the results aren't visible - I just dunno.
 The trouble is that in large part I use MSWord just as a simple word processor. I have absolutely no idea how to get it to create Tables of Contents or Indexes. In my original question (this is a virtual repeat) I was told to read up on those features - somewhat defeats the object of asking a question here!
So how do I start on this project, make use of your macro and conclude it with a list of paragraph headings and the page numbers on which they can be found? I am sure I don't need to supply a sample of the layout of the sort of document I have - nevertheless one is attached. Ignore the contents of the paragraphs - they are irrelevant to what I want to achieve - only the headings matter. I have used Tahoma12pt for the headings.
 Regards
 Patrick

Paragraph-headings-rqd-01.doc
GrahamSkan,
Thanks for your input. I have looked where you have instructed but so far not managed to get it to do anything useful other than for it to tell me there's an error. I really don't know how to get it to work. It's seems really obscure to me. I need a step by step set of instructions.
Patrick
Your paragraph headings do not have a specific paragraph style.

Select one of them and choose Format/Styles and Formatting. In the Style task pane, hover the mouse over the box below the words 'Formatting of the Selected text'. A drop-down arrow will appear at the right of the box. (Why it isn't there all the time so that you don't have to hose over the whole screen looking for 'secret' buttons beats me.) Anyway, click on it and choose Modify...
In the format box, change the style type to Paragraph, and choose Heading 3 (say) for the 'Style based on:' Click OK and close the Style task pane.

Now put the cursor on the document at the start of the text (Ctrl+Home). Insert a page or a Next page section break. Return the cursor to the start of the document.  You should now be able to insert a TOC which lists the headings and the page numbers.
Graham,

I agree with you that at first blush this sounded more like a TOC.  However, I could not figure out how to get
a TOC to sort the items alpahbetically rather than by order of appearance.

Patrick: can you post a sample file?

Regards,

Patrick
Never mind, found the sample :)
Good point. I had forgotten the alphabetic bit. There isn't a switch to change the TOC order.
>Patrick: can you post a sample file?
I posted one a little earlier but here it is again. Completely ignore the contents of the paragraphs as they are irrelelvant.
Patrick

Paragraph-headings-rqd-01.doc
Patrick / Graham,
I have to say that the whole system is obscure in the extreme to produce a Table of Contents. The only trouble is that the TOC is not in alphabetical order. Any idea how I can achieve that. I tried copying and pasting into a table with the intention of then sorting it but it failed to paste the page numbers.
Patrick
Patrick / Graham,
I've now figured it out - all I need to do is to copy and paste the TOC into a single celled Table and then sort it.
Thank you both for your help.
If there's a way of making use of your macro Patrick do please let me know. Although I have a vague idea about VBA in Excel, in Word I haven't a clue.
Patrick
Patrick,

Word VBA is *not* my forte.  I know enought to be dangerous, and I can sometimes muddle through recording
a macro and then cleaning the code, but that's about it.  I cannot figure out why my macro is working on my
test file but not on your sample.  Perhaps Graham can figure that out--he's probably forgotten more about Word
VBA than I would ever know in several lifetimes :)

Nice trick on coopting the TOC.  That could possibly be automated, but I'd leave that to Graham...

Regards,

Patrick
Patrick,
Thanks for your efforts. MS Word's cleverer aspects leave me cold. The Help file is anything but that and I cannot be hacked to buy a book on MSWord. In short MSWord does a basic job for me and little more. Sure I can set up tables, and sometimes even formulae within the tables but there's usually little point in doing that when Excel does it 1000 times better.
I raised this as a question last week and got very annoyed with the potential answerer. His background was publishing - as a result he told me that I HAD to understand and use the MSWord terminology. He also told me to read up on TOC's and Indexes for MSWord. Rather defeated the object of asking the question in the first place. In fact I got so annoyed with him that I even received a rebuking email from a Mod! Ah well, such is life.
Regards
Patrick
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Graham,
Many thanks for that code - it works very well and is exactly what I was needing.
I will be asking a follow-up question and will post the link to it in my next comment.
Patrick