I have created an application to spell check labels (as there is currently no avaliable spell check solution) but I currently use the Word spell checker instead of internal.
I have an issue with this current method. It starts word and runs the check fine however it opens a new document every time and I have to close it manually as well as a few other issues described below.
See code below. My question is simple really. Can I use the internal spell check instead or do I really need to use word?
If I have to use word.
When the spell check window it oonly appears in the background and I have to switch to it, can I force the visibility to front?
When I have finished the document closes but the word application stays open and when closed states that the .dot file has been changed etc, and I have to then answer y/n to save changes in dialogues etc. How can I omit / prevent this?
Code:
Public Sub spellme(ByRef testext As String)
Dim wordApp As New Word.Application
wordApp.Visible = False
Dim doc As Word.Document = wordApp.Documents.Add()
Dim range As Word.Range
range = doc.Range()
range.Text = testext
doc.Activate()
doc.CheckSpelling()
Dim chars() As Char = {CType(vbCr, Char), CType(vbLf, Char)}
testext = doc.Range().Text.Trim(chars)
doc.Close(SaveChanges:=False)
wordApp.Quit()
End Sub
Any help or pointers would be greatly appriciated.
Mike
Solved! Go to Solution.
Solved by MikeEvansUK. Go to Solution.
I have worked out the problem with closing etc.
This now works well using word apart from the text containing /p etc in the text strings obtained.
Still my question regarding the use of internal checker stands.
Oh Dear.
Well it works well however it breaks all the labels it modifies..
Where there is a dynamic link to the civil object eg. <Name> when it replaces the whole text string with what has been changed during the spell check it breaks the dynamic link for the <Name>.
Back to the drawing board with this bit unless somehow there is a way to search the "Olabel.GetTextComponentOverride(Olabelid)" string and not pass the <name> etc over for spelling and then only update the data changed ignoring the <> entries. I think this may not be achievable / easy which is probably why we don't have spell check functionality in labels in the first place.
Ho Hum.
M.
The answer to this was simpler than I thought.
The note label needs a separate sub component added for the notes to be held in. This enable you to search within the text string to find text not containing the <[ characters which will be a dynamic component and check this instead thus leaving the dynamic components alone and not breaking them.
Dim stext As String = Olabel.GetTextComponentOverride(Olabelid)
Dim Slong1 As Char = "<["
' Dim Slong2 As Char = ">"
If Not stext.Contains(Slong1) Then
spellme(Olabel.GetTextComponentOverride(Olabelid))
Olabel.SetTextComponentOverride(Olabelid, TextRes)
Else
End If
Im sure there would be a method to edit text ignoring the <[ ]> strings alone is there but I cant find it (with my simple knowledge).
However the Word spell check is still painful to use in this way. An internal one would be of benefit.