This is topic MS Word assistance in forum Books, Films, Food and Culture at Hatrack River Forum.


To visit this topic, use this URL:
http://www.hatrack.com/ubb/main/ultimatebb.php?ubb=get_topic;f=2;t=039011

Posted by Scott R (Member # 567) on :
 
I need to develop an automated process in MS Word that will find text elements formatted with a CUSTOM style and list them at the bottom of the page.

[Smile]

Any takers?
 
Posted by TomDavidson (Member # 124) on :
 
Will the custom style always have the same name?
 
Posted by Scott R (Member # 567) on :
 
Yes. I'm trying to find some way to list all of the acronyms in a document, so the style will always be 'acronym.'

I've tried using the Index and Table dialogue, modifying the Figures of Tables to match with the style 'acronym,' but can't seem to get it to work...
 
Posted by Dagonee (Member # 5818) on :
 
Make a new momdule in your document with these contents. Then run it.

Change "ACRONYM" to whatever the style name is.

Be sure to work on a backup copy!

code:
Option Explicit

Sub GetAllWordsWithStyle()
Dim rng As Range
Dim itemlist As New Collection
Dim itm As Variant

For Each rng In ActiveDocument.Words
If rng.Style = "ACRONYM" Then
Debug.Print rng.Text
itemlist.Add rng.Text
End If
Next rng

Set rng = ActiveDocument.Range
rng.Collapse wdCollapseEnd
rng.InsertAfter vbCrLf & "Acronyms:"
For Each itm In itemlist
rng.Collapse wdCollapseEnd
rng.InsertAfter vbCrLf & itm
Next itm
End Sub


 
Posted by Scott R (Member # 567) on :
 
Dag:

Thanks-- but the code doesn't seem to do anything but print out the word 'Acronyms:'

I made sure to name the style ACRONYM. . .

?
 
Posted by Scott R (Member # 567) on :
 
I found a temporary work around, as below (this is with Word 2003-- not sure how to do this on any earlier versions).

Before you start writing a doc, create a style called ‘acronym.’ Whenever you add an acronym, select it, and change its style to ‘acronym.’ When you’re ready to insert the Table of Acronyms, click the style button (looks like Aa), and you should see all the Styles available in the document appear on the right side of the screen. Click ‘acronym’ and then click ‘Select all X instances.’ All the words with the style ‘acronym’ will be selected—you can then copy and paste them into a vertical list.
 
Posted by Dagonee (Member # 5818) on :
 
Then there were no words using that style in the document. I beleive style names are case sensitive.

Glad you found a way to do it, though.
 


Copyright © 2008 Hatrack River Enterprises Inc. All rights reserved.
Reproduction in whole or in part without permission is prohibited.


Powered by Infopop Corporation
UBB.classic™ 6.7.2