ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

DonationCoder.com Software > Post New Requests Here

IDEA: VBA (?) Utility to export info on Word 2010 styles to .csv or .txt file

(1/1)

trose:
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:
Check out VBAExpress.  Here's some discussion re what you are looking for:

http://www.vbaexpress.com/forum/showthread.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:
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).


Navigation

[0] Message Index

Go to full version