#1
|
|||
|
|||
Creating a list of all text in a specific style
Hi,
I have created a new style in word and am using this in a document with a large amount of other styles. I need to create a list of the text containing this specific style at the end of the document. Is there a macro that I could use to do this as I need to do it on multiple documents? Thanks |
#2
|
|||
|
|||
What kind of style? Here is one way to list all text with the "Strong" character style applied:
Code:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey Dim oRng As Word.Range Set oRng = ActiveDocument.Range With oRng.Find .Style = "Strong" While .Execute ActiveDocument.Range.InsertAfter vbCr & oRng ActiveDocument.Paragraphs.Last.Range.Style = "Normal" oRng.Collapse wdCollapseEnd Wend End With End Sub |
#3
|
|||
|
|||
Error message?
Hi,
The style I am using is my own custom style and it is called "Glossary Pop-up" would that cause an issue at all? When I run the macro nothing happens? Thanks |
#4
|
|||
|
|||
I created a style call Glossary Pop-up and it worked fine. Without seeing your document, it is hard to say.
Did you run the code or try to run it I break mode? |
#5
|
|||
|
|||
runnning the style
Sorry, I am pretty new to this! What is the difference between running the code and in break mode?
Thanks again |
#6
|
|||
|
|||
Stepping throughout the code using the F8 key would be one example of break mode. Clicking in the procedure and select "Run" would run the code.
|
#7
|
|||
|
|||
Run code
I have used the run code.
It is strange, I have opened up a new docuemnt and used the macro on a small amount of text but when I use it on a larger document with lots of other styles (including headings etc) it does not work? |
#8
|
|||
|
|||
Would have to see the document.
|
#9
|
|||
|
|||
Attached document
]Hi,
I have attached a text document if that is any help? Last edited by ljd108; 10-08-2014 at 05:24 PM. |
#10
|
|||
|
|||
Code runs fine here in that document. It does not contain any text formatted with Glossary Pop-up style though.
|
#11
|
|||
|
|||
Response
Hi,
Thanks for taking a look, I do have words selected as 'glossary pop-up' in mine, these are only 'characters' rather than 'paragraphs' though, does that make a difference? Thanks |
#12
|
|||
|
|||
Ok, I see it now still runs without error. Change to this and it runs and adds your Words to the end:
Code:
Sub ScratchMacro() 'A basic Word macro coded by Greg Maxey Dim oRng As Word.Range Set oRng = ActiveDocument.Range With oRng.Find .Style = "Glossary Pop-up Char" While .Execute ActiveDocument.Range.InsertAfter vbCr & oRng ActiveDocument.Paragraphs.Last.Range.Style = "Normal" oRng.Collapse wdCollapseEnd Wend End With End Sub |
#13
|
|||
|
|||
Fantastic
Thank you very very much, all works fine now
|
#14
|
|||
|
|||
Another question
Sorry to add another question.
Is there also a way of creating a list of text that is not using the style set within a document? |
#15
|
|||
|
|||
All text in a document has some style applied so it is therefore impossible to add a list at the end of a document that in not styled with a style contained in the document.
|
Tags |
macro, styles |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to set the left indent in a specific style. | OfficeBoy95 | Word | 2 | 05-12-2014 06:31 PM |
List Style Numbering picks up out of order number from LATER list | spthomas | Word | 12 | 12-16-2013 05:23 PM |
How to set style automatically for specific texts | ragesz | Word | 2 | 07-25-2013 07:08 AM |
I create a new style but it fails to appear in Quick Style list | veronius | Word | 6 | 06-18-2013 06:29 PM |
Get list of text of a style | mavera2 | Word | 0 | 03-19-2010 01:59 AM |