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.
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
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?
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
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.
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
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).
your ratings show me that my time means something to you. please show it.
put [HIGHLIGHT="vb"][/HIGHLIGHT] around code
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.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum.
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?
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
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
Last edited by dee-u; Sep 3rd, 2009 at 10:37 AM.
Regards,
™
As a gesture of gratitude please consider rating helpful posts. c",)
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,...
*** Read the sticky in the DB forum about how to get your question answered quickly!! ***
Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".
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
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.
On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
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
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.
C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter
There's just no reason to use garbage like InputBox. - jmcilhinney
The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber
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.