I've got a VB.NET application which I am working on which uses the Word spellchecking feature. I've tried numerous things to get the dialog box for the spellchecker to pop-up on top of all the other windows, but it doesn't work. Below is the code for the function which I have tried to make work - as you can see I tried .Show, .Active and .Topmost, but no matter what the dialog box is hidden under my windows:
Thanks,
Jeff
Code:
Public Function CheckString(ByRef str As String) As String
Dim app As Application = New Word.Application
Dim doc As Document = app.Documents.Add
app.Selection.Text = str
Try
Dim dlg As Word.Dialog
dlg = app.Dialogs.Item(Word.WdWordDialog.wdDialogToolsSpellingAndGrammar)
Dim oldFilter As IOleMessageFilter = Nothing
Dim nullFilter As IOleMessageFilter = Nothing
CoRegisterMessageFilter(nullFilter, oldFilter)
Try
dlg.Show()
dlg.Active()
dlg.TopMost = True
Finally
CoRegisterMessageFilter(oldFilter, oldFilter)
End Try
app.Visible = False
Dim docRange As Range = doc.Content
str = docRange.Text
str = str.TrimEnd(Environment.NewLine)
Catch e As Exception
System.Diagnostics.Trace.WriteLine("Spell checking...")
System.Diagnostics.Trace.WriteLine(e.ToString)
Finally
doc.Close(WdSaveOptions.wdDoNotSaveChanges)
app.Quit()
End Try
Return str
End Function
Thanks,
Jeff