|
-
Oct 1st, 2004, 06:14 AM
#1
SPELL CHECK and WORD
We just started using WORD to SPELL CHECK a textbox from VB.
I have noticed, as well as some users testing it out, that if they have WORD open already (like sending an OUTLOOK e-mail or actually editing a WORD doc), the spell check window doesn't appear on top of our application. Things kind of get stuck...
They have to use TASK MANAGER to kill our app - which then causes the WORD app to appear on screen - along with the spell check box, with our TEXTBOX info sitting in WORD.
This was our first attempt at automation, so I'm sure we missed some key point somewhere...
Thanks for the help.
-
Oct 1st, 2004, 10:07 AM
#2
Find any post by Martin Liss, his signature has a link that shows how to spellcheck with word. The procedure might even be in the Code Bank.
For now, instead of killing the app use Alt-Tab to get to the spell check window.
-
Oct 1st, 2004, 11:00 AM
#3
I used the code in the MARTIN LISS posting - from his signature/code bank. That's what has me so puzzled...
ALT-TAB didn't seem to work - I'll try to duplicate problem here and see if ALT-TAB does work...
As far as automation goes - when you "start an instance" of WORD and WORD is already running, are you becoming part of that instance (since WORD is a MDI-parent/child kind of app??). Should I be killing the WORD app at the exit of my app, if I didn't really start it?
-
Oct 1st, 2004, 11:17 AM
#4
I havent seen Martins code but what I do is check to see if
Word is running and if it is I attach my Word application object to
it. If its not running I create a new one.
Nothing new there, but when I start manipulating Word I set its
visible property to false. Then I make the window minimized and
set up the spell checking dialog box. Set its visible property to
true and then display the spellchecking dialog box. I havent run
into any issues yet so I think its stable. Maybe try something like
this will work for you.
HTH
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Oct 1st, 2004, 01:54 PM
#5
RobDog888
This has been our first venture into automation - so I'm unclear on how to actually perform the changes you suggest.
This is the actual function that I ripped from the MartinLiss posting. We changed the objWord to a PUBLIC object so that it would persist - allowing subsequent calls to CHECKSPELLING to be faster. And we put the CLOSE WORD logic in QUERY UNLOAd
VB Code:
Public objWord As Object
Public Function CheckSpelling(t As TextBox)
On Error GoTo Err_Handler
Dim s1 As String
s1 = lblState.Caption
' 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
lblState.Caption = "Checking Spelling now!"
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:
lblState.Caption = s1
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
VB Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Debug.Print "Form_QueryUnload with State="; gbytState
If Not (objWord Is Nothing) Then
Debug.Print "Form_QueryUnload>Word QUIT"
objWord.Application.Quit True
End If
Set objWord = Nothing
If gbytState >= 5 Then
If setState(7) <> 7 Then Cancel = True
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|