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.
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
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"