PDA

View Full Version : Get all properties of a style - use strings stored in an array as property name



mkofler
09-24-2013, 07:34 PM
Hi
I want to loop thru all the styles in a document and print out their properties. As there are a large amount of properties, I store the names of the properties in an array. I want to loop thru the array to the get names of the property I want to display.
How do I use the strings in the array as the property names in the following code?



Dim arrStyleProps a string
Dim style as Style

arrStyleProps = Array("Application", "Automatically Update", "BaseStyle", _
"Borders", "BuiltIn ", "Creator", "Description", "Font", _
"Frame", "In Use", "Language ID", "Language ID Far East", "Linked", _
"Link Style", "List Level Number", "ListTemplate", "Locked ", _
"NameLocal", "NextParagraphStyle", "NoProofing", "No Space Between Paragraphs Of Same Style", _
"Paragraph Format", "Parent", "Priority", "QuickStyle", "Shading", _
"Table", "Type", "Unhide When Used", "Visibility")

For Counter = 0 To UBound(arrStyleProps)

For Each style In ActiveDocument.Styles
debug.print style.arrStyleProps(counter)
next style
next counter

mkofler
09-25-2013, 12:22 AM
I found the answer was to use the CallByNameFunction.
This code works and displays all the paragraph format properties of the styles in a document. Hope this helps someone else.


Dim arrStyleProps
Dim style As style
Dim icounter As Integer
Dim result As String
Dim soutput As String
On Error Resume Next


arrParagraphFormatProps = Array("AddSpaceBetweenFarEastAndAlpha", "AddSpaceBetweenFarEastAndDigit", "Alignment", _
"Application", "AutoAdjustRightIndent", "BaseLineAlignment", "Borders", "CharacterUnitFirstLineIndent", _
"CharacterUnitLeftIndent", "CharacterUnitRightIndent", "Creator", "DisableLineHeightGrid", "Duplicate", _
"FarEastLineBreakControl", "FirstLineIndent", "HalfWidthPunctuationOnTopOfLine", "HangingPunctuation", _
"Hyphenation", "KeepTogether", "KeepWithNext", "LeftIndent", "LineSpacing", "LineSpacingRule", _
"LineUnitAfter", "LineUnitBefore", "MirrorIndents", "NoLineNumber", "OutlineLevel", "PageBreakBefore", _
"Parent", "ReadingOrder", "RightIndent", "Shading", "SpaceAfter", "SpaceAfterAuto", "SpaceBefore", "SpaceBeforeAuto", "TabStops", "TextBoxTightWrap", "WidowControl", "WordWrap")


For Each style In ActiveDocument.Styles
soutput = "Style Name: " & style & vbCrLf

For icounter = 0 To UBound(arrParagraphFormatProps)

If style.Type = 1 And style.BuiltIn = False Then
result = CallByName(style.ParagraphFormat, arrParagraphFormatProps(icounter), VbGet)
soutput = soutput & "Property: " & arrParagraphFormatProps(icounter) & " " & "Value: " & result
Selection.TypeText (soutput & vbCrLf)
soutput = ""
End If

Next icounter

Next style

Frosty
09-25-2013, 02:57 PM
Interesting, I didn't know about CallByName. To your original question, not sure if this is helpful... but the .Description property of a style will give you a lot of the info you're looking for, in a string property