The VBA macro would be:
Code: Select all
Selection.HomeKey Unit:=wdStory
Dim oSE As Range, oGE As Range
For Each oSE In ActiveDocument.SpellingErrors
oSE.HighlightColorIndex = wdYellow
Next
lbl_Exit:
Exit Sub
End Sub
Code: Select all
Selection.HomeKey Unit:=wdStory
Dim oSE As Range, oGE As Range
For Each oSE In ActiveDocument.SpellingErrors
oSE.HighlightColorIndex = wdYellow
Next
lbl_Exit:
Exit Sub
End Sub
Here is a first attempt:REH-CAE-RPT wrote:Does anybody know a way to highlight all spelling errors within a document
Code: Select all
sub highlight_spell_errors(optional container)
if ismissing(container) then
container = thiscomponent
end if
' get text object
T = container.Text
' get text cursor
cursor = T.createTextCursor()
' get spell checker service
lsm = createUnoService("com.sun.star.linguistic2.LinguServiceManager")
spellchecker = lsm.getSpellchecker()
' bypassing an uno api bug which confuse between XSpellChecker and XSpellChecker1
reflector = createUnoService("com.sun.star.reflection.CoreReflection")
xspellchecker = reflector.forName("com.sun.star.linguistic2.XSpellChecker")
isvalid = xspellchecker.getMethod("isValid")
' iterate through all words
dim props() as new com.sun.star.beans.PropertyValue
do
cursor.gotoStartOfWord(False)
cursor.gotoEndOfWord(True)
word = cursor.String
if not isValid.invoke(spellchecker, array(word, cursor.CharLocale, props())) then
cursor.CharBackColor = 16776960
end if
cursor.gotoNextWord(False)
if cursor.isEndOfParagraph then
cursor.gotoNextParagraph(False)
end if
loop while T.compareRegionEnds(T, cursor) <> 0
' check sub texts
frames = container.TextFrames
for each frame in frames
on error resume next
highlight_spell_errors(frame)
next frame
tables = container.TextTables
for n = 0 to tables.Count -1
table = tables(n)
cellnames = tables(n).CellNames
for each cellname in cellnames
cell = table.getCellByName(cellname)
highlight_spell_errors(cell)
next cellname
next n
end sub
Edit: I had infact some problems with AOO, due to erroneous basic syntax. Could you please try this new one? The change is in the do...loop loop: Code: Select all
|
Code: Select all
lp = createUnoService("com.sun.star.linguistic2.LinguProperties")
lp.setPropertyValue("IsSpellUpperCase", True)