JoseC
Programmer
- Dec 11, 2001
- 18
I got the code below to work. I even copy the current clipboard content and restore it later 'cause the spellcheck process erases it.
Anyhow, at times; there will be a delay or something that will display a "SWITCH TO application" or "RETRY" message box that appears to the user. My current assumption is that perhaps the CreateObject took a while and could open the instance of WORD.
How do I increase the timeout??
or what do I do so the user doesn't see that?
'----------------------------------------------------------
Function MsSpellCheck(strText As String) As String
'*** Before doing spell check, copy any ClipBoard text to a variable
'*** for temporary storage.
Dim tempClipBoardText As String
tempClipBoardText = Clipboard.GetText(1)
'MsgBox tempClipBoardText
'*** The MsSpellCheck will perform the following:
'*** 1. Create an object instance of MS WORD
'*** 1. Start a new document
'*** 1. Paste the passed text onto the document
'*** 1. Select all text in document
'*** 1. Perform spell check
'*** 1. Copy all now corrected text onto clipboard
'*** 1. Set text from clipboard onto variable
'*** 1. Close MS WORD
'*** 1. Destroy MS WORD object instance
Dim oWord As Object
Dim strSelection As String
Set oWord = CreateObject("Word.Basic"
oWord.AppMinimize
MsSpellCheck = strText
oWord.FileNewDefault
oWord.EditSelectAll
oWord.EditCut
oWord.Insert strText
oWord.StartOfDocument
On Error Resume Next
oWord.ToolsSpelling
On Error GoTo 0
oWord.EditSelectAll
strSelection = oWord.Selection$
If Mid(strSelection, Len(strSelection), 1) = Chr(13) Then
strSelection = Mid(strSelection, 1, Len(strSelection) - 1)
End If
If Len(strSelection) > 1 Then
MsSpellCheck = strSelection
End If
oWord.FileCloseAll 2
oWord.AppClose
Set oWord = Nothing
'*** After doing spell check, copy any variable text onto ClipBoard
'*** that way, user will have any before MsSpellCheck process ClipBoard text back again.
Clipboard.SetText tempClipBoardText, 1
End Function
'----------------------------------------------------------
Anyhow, at times; there will be a delay or something that will display a "SWITCH TO application" or "RETRY" message box that appears to the user. My current assumption is that perhaps the CreateObject took a while and could open the instance of WORD.
How do I increase the timeout??
or what do I do so the user doesn't see that?
'----------------------------------------------------------
Function MsSpellCheck(strText As String) As String
'*** Before doing spell check, copy any ClipBoard text to a variable
'*** for temporary storage.
Dim tempClipBoardText As String
tempClipBoardText = Clipboard.GetText(1)
'MsgBox tempClipBoardText
'*** The MsSpellCheck will perform the following:
'*** 1. Create an object instance of MS WORD
'*** 1. Start a new document
'*** 1. Paste the passed text onto the document
'*** 1. Select all text in document
'*** 1. Perform spell check
'*** 1. Copy all now corrected text onto clipboard
'*** 1. Set text from clipboard onto variable
'*** 1. Close MS WORD
'*** 1. Destroy MS WORD object instance
Dim oWord As Object
Dim strSelection As String
Set oWord = CreateObject("Word.Basic"
oWord.AppMinimize
MsSpellCheck = strText
oWord.FileNewDefault
oWord.EditSelectAll
oWord.EditCut
oWord.Insert strText
oWord.StartOfDocument
On Error Resume Next
oWord.ToolsSpelling
On Error GoTo 0
oWord.EditSelectAll
strSelection = oWord.Selection$
If Mid(strSelection, Len(strSelection), 1) = Chr(13) Then
strSelection = Mid(strSelection, 1, Len(strSelection) - 1)
End If
If Len(strSelection) > 1 Then
MsSpellCheck = strSelection
End If
oWord.FileCloseAll 2
oWord.AppClose
Set oWord = Nothing
'*** After doing spell check, copy any variable text onto ClipBoard
'*** that way, user will have any before MsSpellCheck process ClipBoard text back again.
Clipboard.SetText tempClipBoardText, 1
End Function
'----------------------------------------------------------