Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 02, 2016, 06:17:09 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: IDEA: VBA (?) Utility to export info on Word 2010 styles to .csv or .txt file  (Read 2940 times)

trose

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 2
    • View Profile
    • Donate to Member
IDEA: VBA (?) Utility to export info on Word 2010 styles to .csv or .txt file

I am looking for a utility or VBA script that would extract information on all styles available in a specified Word 2010 document and send that information to a .csv or .txt file. I believe there are standard attributes or properties for Word styles, and the exported file should be organized according to those standard properties.

The output file should look something like this:

Style Name 1
Font Name:
Font Size:
Style Type: Character, Paragraph, or both
etc...

If anybody can suggest a script or utility that would do this, that would be very helpful.

Thanks for your time.



AndyM

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 616
    • View Profile
    • Donate to Member
Check out VBAExpress.  Here's some discussion re what you are looking for:

http://www.vbaexpres...owthread.php?t=36546

In that thread there is simple code to list the styles available:
Public Sub SampleMyStyles()
    Dim mySty As Style
    With ActiveDocument
        For Each mySty In .Styles
            If .Styles(mySty.NameLocal).InUse = True Then
                Selection.TypeText mySty.NameLocal & vbCr
            End If
        Next
    End With
End Sub
But seeing only the styles currently in use requires extra steps, discussed in the thread.

This code just outputs the styles into the current document at the current cursor position, which is fine for testing the output if you put the cursor at the end of the file. Output into a separate text file would not be too difficult.  Someone at VBAExpress can tell you if there are parameters to list Font Name, Size, etc.

kfitting

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 578
    • View Profile
    • Donate to Member
Ouput to textfile is not real hard... there are a couple ways to do it.  You can read up on the Textstream object (I forget which reference you need to add to enable it) or you can use Open, Close statements:

Open "C:\textfile.txt" for Output as #1

Write #1, "This is line 1"
Write #1, "This is line 2"

Close #1

I wrote a class around the textstream object so have not used Open/Close in a long time.

Regarding styles, you can easily output properties.  Use the loop above, and into the IF statement you can add all sorts of things:

mySty.ParagraphFormat.Alignment
mySty.Font.Color
mySty.Font.Name
mySty.InUse      'This should be the same property as what is tested in the IF statement above... just a shorter way to get it.
mySty.BaseStyle

The best way to check this out is to go into the VBA editor, copy and paste the code AndyM gave you and then type "mySty." so the property helper comes up... you can see all the properties to play with them (you can also hit F2 to go to the object browser).