-
Can't get WORD CHECK SPELLING window to be ON TOP always
I'm having a problem where the WORD window for CHECK SPELLING doesn't always appear on top of my app.
I've isolated the code into this simple example - create a new project with two textboxes - TEXT1 and TEXT2 - make both multi-line
Put this code into FORM1
Code:
Public objWord As Object
Private Sub Text1_LostFocus()
Call CheckSpelling(Text1)
End Sub
Private Sub Text2_LostFocus()
Call CheckSpelling(Text2)
End Sub
Public Function CheckSpelling(t As TextBox)
On Error GoTo Err_Handler
' Dim objWord As Object
Dim objDoc As Object
Dim strResult As String
'Create a new instance of word Application
If (Len(t.Text) = 0) Then
'nahhhhhhhhhhh
Else
App.OleRequestPendingTimeout = 999999
If objWord Is Nothing Then Set objWord = CreateObject("word.Application")
objWord.Visible = False
Select Case objWord.Version
'Office 2000, xp, 2k3
Case "9.0", "10.0", "11.0"
Set objDoc = objWord.Documents.Add(, , 1, True)
'Office 97
Case Else
Set objDoc = objWord.Documents.Add
End Select
objDoc.Content = t.Text
objDoc.CheckSpelling
objWord.Visible = False
strResult = Left(objDoc.Content, Len(objDoc.Content) - 1)
'correct the carriage returns
strResult = Replace(strResult, Chr(13), Chr(13) & Chr(10))
If t.Text = strResult Then
' There were no spelling errors, so give the user a
' visual signal that something happened
'MsgBox "The spelling check is complete.", vbInformation + vbOKOnly, "Spelling Complete"
End If
'Clean up
objDoc.Close False
Set objDoc = Nothing
'objWord.Application.Quit True
'Set objWord = Nothing
' Replace the selected text with the corrected text. It's important that
' this be done after the "Clean Up" because otherwise there are problems
' with the screen not repainting
t.Text = strResult
End If
Done:
Exit Function
'in case user does not have word...
Err_Handler:
MsgBox Err.Description & Chr(13) & Chr(13) & "Please note you must have Microsoft Word installed to utilize the spell check feature.", vbCritical, "Error #: " & Err.Number
Resume Done
End Function
Now enter something in TEXT1 and TAB to TEXT2 - so the LOST FOCUS event calls the WORD object to check the spelling.
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
I didn't see it at all until I change objWord.Visible = False to objWord.Visible = True and then the word document that text1 got dumped to was displayed, full screen, and on top of everything.
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
You do not want the WORD window to appear itself - just the spell check window. Thus the reason for that being FALSE.
Alt/Tab will bring the spell check window round front if it doesn't appear so naturally.
I get it appearing in front - most of the time. Change the app from full screen to partial - I'm trying to find a reason for why it sometimes doesn't appear in front.
Is it only if you have OUTLOOK open using WORD - or WORD itself open - how can I guarantee that the SPELL CHECK window always appears in front?
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
The spell check window itself, for me anyway, pops up as a modal window...I can't get rid of it from being on top unless I close it.
I have both Outlook and Word open and I ran my test app at partial screen.
Are there other things going on on your machine that I should try?
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
it works well in my pc :confused:
no problem, when tabbing, the spell window appear on top the form as vbmodal.
what wrong in your system :confused: i have word2003
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
It mostly always works for me on my machine - it's my customers that complain about it intermittently.
Thus they hate it.
Compile the project. Run the .exe.
Maximize the window.
Put dddd into text1 - click tab.
You will most likely get the SPELL CHECK window to appear.
Hit ALT/TAB - the SPELL CHECK window disappears and now just the .exe is full screen.
This is the condition that my clients sometimes have happen - the spell check window is below the app window. I tell them to click ALT/TAB to remedy this - but that is cheesy and they don't like it.
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
I don't know why it would go behind sometimes, but I have seen behavior like this before. Could you add some code to always bring it to the front? You could use the BringWindowToTop API.
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
There is a "Always on top" link in my sig, which is pretty much the standard method.
If it brings it to the top only when the function is called, but it's not on top permanently (very rare), then throw it is a short duration timer (like 500ms).
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
Still having this problem...
Lots of searching the internet today and found this KB article and I'm trying this to see if it works better.
http://support.microsoft.com/kb/243844/
I'll post back with results
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
I tried repositioning Word off screen before when I was developing my Spellchecker but found it added more issues then it solved. If the user opens word during your spellchecking or if there is an issue and it doesnt get repositioned back to original then the user when opens word for normal use will not be able to see it at all since its of screen. If they maximize Word that will present it but then for them to resize it it needs to be normal size but that will position it off screen still. Pain in the butt.
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
wow - that stinks.
and this is the official MS implementation!
Maybe I won't reposition it at all - having the WORD doc appear can be explained to 5 users in a law office. It's better then "oh - the spell check window is hidden - just click alt/tab to find it!"
I found other articles on MSDN that said spell check with WORD was not recommended or supported - I can see why.
How does ACCESS do the spell check so that it's not buggy?
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
Quote:
Originally Posted by
szlamany
How does ACCESS do the spell check so that it's not buggy?
Probably MS uses its spell checking libraries without needing all of Word.
-
1 Attachment(s)
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
A trick which seem to work is to use SetParent API to make the Word object a child of the form so that the dialog is effectively owned by the form itself. The trick is to catch the creation of the word window and I used Penagates sample for that. You just have to compile the project and put that in your own directory and shell it from there.
The event the does the job is the following:
Code:
Private Sub IShell_WindowCreated(ByVal hWnd As Long)
Dim sClassName As String
sClassName = Space(255)
GetClassName hWnd, StrPtr(sClassName), 255
'check if the word class
If (Left$(sClassName, 7) = "OpusApp") Then
LockWindowUpdate GetDesktopWindow
'Hide window
ShowWindow hWnd, 0
'set parent to the caller
SetParent hWnd, callerHandle
LockWindowUpdate 0
Unload Me
End If
End Sub
And here would be the slight modification to the spell checker procedure.
Code:
App.OleRequestPendingTimeout = 999999
If objWord Is Nothing Then Set objWord = CreateObject("word.Application")
'shell the exe with together with the handle of the form or a handle of a hidden picturebox control
Shell "Project1.exe " & Picture1.hWnd, vbHide
objWord.Visible = True
Select Case objWord.Version
'Office 2000, xp, 2k3
Case "9.0", "10.0", "11.0"
Set objDoc = objWord.Documents.Add(, , 1, True)
'Office 97
Case Else
Set objDoc = objWord.Documents.Add
End Select
objDoc.Content = t.Text
objDoc.CheckSpelling
'objWord.Visible = False
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
And still a few years later, has anyone managed to solve this one particular annoying problem when hooking into Word's spell check?
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
Not that I am aware of. This bothered my clients so much that we abandoned our Winform app and created a web-app with ajax/jQuery and tell them all to use Firefox which has spell check built in.
I wonder if MS is aware of how bad this looks to users - WORD hidden or messed up by Outlook - yuk,...
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
I've been putting up with this within an internal company app for several years. It's been a unsightly wart on an important internal app in my company. Staff size is small, so I can educate users on resolving a seemingly frozen app during spell check; but now we're moving the app toward a vertical resale market with our clients, and I'll need to get this resolved or replace the functionality. The most frustrating part about it is you can't duplicate it on demand. If you could, somebody could likely provide a work-around.
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
It looks like the code is based on my Spell Check a Textbox that I mentioned above. Take a look at that code and see what's different.
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
It seems to have even gotten worse with Windows 7 as well - not sure about Windows 8...
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
Quote:
Originally Posted by
MartinLiss
It looks like the code is based on my Spell Check a Textbox that I mentioned above. Take a look at that code and see what's different.
It's the same code. You even made mention this problem in that other thread, writing:
"Three problems have been reported by rike when using my code in VBA. Those problems are:
1. ...
2. ...
3 When users try to use other applications while the spellchecker is in progress the screen gets confused and appears to crash."
As I wrote, I've never figured out how to duplicate it since it's some kind of timing issue. You can simulate the behavior by running in design mode and setting a breakpoint on the .CheckSpelling method, then step to the next line. At least that's how I remember doing it.
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
So years later, looks like this continues to be a flawed means of Spell check.
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
I am sure you could pay dollars for a product that would fulfill your needs in a more robust and bug-free way.
When life get's tough you just gotta pay your way out...
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
Perhaps you'd like to try something else?
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
Had this same problem. I used this as a workaround:
Code:
'Hide all open forms
For Each f As Form In My.Application.OpenForms
f.Hide()
Next
doc.Activate()
doc.CheckSpelling()
'Show all forms after spell check
For Each f As Form In My.Application.OpenForms
f.Show()
Next
It's more of a workaround than anything.
- Mark
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
Note that this is a VB6 thread.
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
And a thread that is 15 months old :)
-
SOLVED: Re: Can't get WORD CHECK SPELLING window to be ON TOP always
I solved this.
When you are testing the spellchecker with vb6 running. The spellchecker stays at the back.
You need to first make all of your open application forms invisible like this.
UserForm1.visible = false
UserForm2.visible = false.
Then call the activedocument.spellchecker
Then make all your forms visible again
after spellchecker is finished.
Now when you make the executable file and test it with vb6 closed, the word document will be in front with the spellchecker also in front.
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
You do realize that this thread is 13 years old?
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
Quote:
Originally Posted by
Niya
You do realize that this thread is 13 years old?
I also appreciate his dedication to getting the correct answer. Good job Code Tech! :bigyello:
We should work on this until 2034. It is the only way to be sure.
!remindme in 12 years
-
Re: Can't get WORD CHECK SPELLING window to be ON TOP always
Guess I been sleeping that long. LOL
Actually I just pulled out an old VB6 application that I wrote so that I could convert it to vb.net but I had to fix the spellchecker issue 1st.