Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-08-2014, 10:48 AM
ljd108 ljd108 is offline Creating a list of all text in a specific style Windows Vista Creating a list of all text in a specific style Office 2010 32bit
Novice
Creating a list of all text in a specific style
 
Join Date: Oct 2014
Posts: 24
ljd108 is on a distinguished road
Default 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
Reply With Quote
  #2  
Old 10-08-2014, 01:15 PM
gmaxey gmaxey is offline Creating a list of all text in a specific style Windows 7 32bit Creating a list of all text in a specific style Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 10-08-2014, 03:29 PM
ljd108 ljd108 is offline Creating a list of all text in a specific style Windows Vista Creating a list of all text in a specific style Office 2010 32bit
Novice
Creating a list of all text in a specific style
 
Join Date: Oct 2014
Posts: 24
ljd108 is on a distinguished road
Default 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
Reply With Quote
  #4  
Old 10-08-2014, 03:33 PM
gmaxey gmaxey is offline Creating a list of all text in a specific style Windows 7 32bit Creating a list of all text in a specific style Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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?
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 10-08-2014, 03:37 PM
ljd108 ljd108 is offline Creating a list of all text in a specific style Windows Vista Creating a list of all text in a specific style Office 2010 32bit
Novice
Creating a list of all text in a specific style
 
Join Date: Oct 2014
Posts: 24
ljd108 is on a distinguished road
Default runnning the style

Sorry, I am pretty new to this! What is the difference between running the code and in break mode?

Thanks again
Reply With Quote
  #6  
Old 10-08-2014, 03:44 PM
gmaxey gmaxey is offline Creating a list of all text in a specific style Windows 7 32bit Creating a list of all text in a specific style Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #7  
Old 10-08-2014, 03:46 PM
ljd108 ljd108 is offline Creating a list of all text in a specific style Windows Vista Creating a list of all text in a specific style Office 2010 32bit
Novice
Creating a list of all text in a specific style
 
Join Date: Oct 2014
Posts: 24
ljd108 is on a distinguished road
Default 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?
Reply With Quote
  #8  
Old 10-08-2014, 04:08 PM
gmaxey gmaxey is offline Creating a list of all text in a specific style Windows 7 32bit Creating a list of all text in a specific style Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Would have to see the document.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #9  
Old 10-08-2014, 04:17 PM
ljd108 ljd108 is offline Creating a list of all text in a specific style Windows Vista Creating a list of all text in a specific style Office 2010 32bit
Novice
Creating a list of all text in a specific style
 
Join Date: Oct 2014
Posts: 24
ljd108 is on a distinguished road
Default 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.
Reply With Quote
  #10  
Old 10-08-2014, 05:02 PM
gmaxey gmaxey is offline Creating a list of all text in a specific style Windows 7 32bit Creating a list of all text in a specific style Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Code runs fine here in that document. It does not contain any text formatted with Glossary Pop-up style though.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #11  
Old 10-08-2014, 05:09 PM
ljd108 ljd108 is offline Creating a list of all text in a specific style Windows Vista Creating a list of all text in a specific style Office 2010 32bit
Novice
Creating a list of all text in a specific style
 
Join Date: Oct 2014
Posts: 24
ljd108 is on a distinguished road
Default 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
Reply With Quote
  #12  
Old 10-08-2014, 05:20 PM
gmaxey gmaxey is offline Creating a list of all text in a specific style Windows 7 32bit Creating a list of all text in a specific style Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #13  
Old 10-08-2014, 05:22 PM
ljd108 ljd108 is offline Creating a list of all text in a specific style Windows Vista Creating a list of all text in a specific style Office 2010 32bit
Novice
Creating a list of all text in a specific style
 
Join Date: Oct 2014
Posts: 24
ljd108 is on a distinguished road
Default Fantastic

Thank you very very much, all works fine now
Reply With Quote
  #14  
Old 10-08-2014, 05:35 PM
ljd108 ljd108 is offline Creating a list of all text in a specific style Windows Vista Creating a list of all text in a specific style Office 2010 32bit
Novice
Creating a list of all text in a specific style
 
Join Date: Oct 2014
Posts: 24
ljd108 is on a distinguished road
Default 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?
Reply With Quote
  #15  
Old 10-08-2014, 06:40 PM
gmaxey gmaxey is offline Creating a list of all text in a specific style Windows 7 32bit Creating a list of all text in a specific style Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,429
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

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.
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply

Tags
macro, styles



Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a list of all text in a specific style How to set the left indent in a specific style. OfficeBoy95 Word 2 05-12-2014 06:31 PM
Creating a list of all text in a specific style 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
Creating a list of all text in a specific style 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

Other Forums: Access Forums

All times are GMT -7. The time now is 01:00 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft