Applescript for Word 2008 - Styles in use

Hi all,
I’m very stuck, and I’m hoping for some help.

I’m trying to write a macro to show all styles in use in a Word doc. Below is the start of the macro.

The problem with this is, it takes forever to do a search for every style.

There’s a property “Word styles in use”, per the link below, but I can’t seem to figure out what is the proper syntax to get it to work. Any suggestions? It seems like it would be a much simpler solution.

http://www.microsoft.com/mac/developers/default.mspx?MODE=ct&CTT=PageView&clr=99-25-0&target=959197a9-053f-4813-b790-3d8cb64d1c421033&srcid=&ep=8&rtype=2&pos=7&quid=53eb40d3-58ab-4a4d-813b-20851cfe6468

Thanks
John

tell application "Microsoft Word"
    
    set StyleList to {}
    set StyleList to name local of Word styles of active document
    set ItemCount to count StyleList
    
    set i to 1
    
    repeat while i < ItemCount + 1
        
        set CurrentStyle to item i of StyleList
        
        home key selection move unit a story extend by moving
        set selFind to find object of selection
        tell selFind
            clear formatting
            set content to ""
            set style to CurrentStyle
            clear formatting of selFind's replacement
            execute find wrap find find stop ¬
                with match forward
            
            if selFind is found then
                display dialog CurrentStyle
            end if
            
        end tell
        
        
        set i to i + 1
        
    end repeat
    
end tell

I get a list of the used paragraph styles using the following code:


tell application "Microsoft Word"
	set the clipboard to ""
	activate
	tell application "System Events"
		keystroke "a" using command down
	end tell
	activate
	
	set theParagraphs to paragraphs of selection
	
	set listOfNames to {}
	delay 0.5
	repeat with aParagraph in theParagraphs
		set nameOfStyle to name local of style of aParagraph
		if nameOfStyle is not in listOfNames then set end of listOfNames to nameOfStyle
	end repeat
	
	
	set oldDelim to AppleScript's text item delimiters
	set AppleScript's text item delimiters to return
	set theResultString to listOfNames as text
	set numberOfResutls to count items of listOfNames
	set AppleScript's text item delimiters to oldDelim
	display dialog "The used styles on the active Word document are " & numberOfResutls & ":" & return & theResultString buttons "OK"
end tell

Hi,

neither GUI scripting nor selecting the text is needed


tell application "Microsoft Word"
	set theParagraphs to paragraphs of active document
	
	set listOfNames to {}
	repeat with aParagraph in theParagraphs
		set nameOfStyle to name local of style of aParagraph
		if nameOfStyle is not in listOfNames then set end of listOfNames to nameOfStyle
	end repeat
end tell

set oldDelim to text item delimiters
set text item delimiters to return
set theResultString to listOfNames as text
set numberOfResutls to count items of listOfNames
set text item delimiters to oldDelim
display dialog "The used styles on the active Word document are " & numberOfResutls & ":" & return & theResultString buttons "OK"