-
Mar 17th, 2004, 11:49 PM
#1
VBScript Spellchecking
The following is the code used by the Forum tool referred to in my signature. It has a couple of problems, the most annoying of which is that when it finds a misspelled word, the spelling correction window does not display on top. The same thing happens when the spelling check is complete. Is there any way to have it display on top?
VB Code:
<!--
+---------------------------------------------------------------------------+
Function: Spell Checker
Description: This script uses Microsoft Word to check the spelling in
posts. Word is assumed to be present.
+---------------------------------------------------------------------------+
-->
<SCRIPT LANGUAGE = "VBScript">
Dim objWord
Dim objDoc
Dim objWindow
Dim objSource
Dim objSelect
Dim objSelectRange
Dim strResult
Set objWindow = window.external.menuArguments
Set objSource = objWindow.event.srcElement
Set oDocument = objWindow.document
Set objSelect = oDocument.selection
Set objSelectRange = objSelect.createRange()
'Create a new instance of word Application
Set objWord = CreateObject("word.Application")
If objSource.tagName = "TEXTAREA" Then
select case objWord.version
'Office 2000
case "9.0"
with objWord
.WindowState = 2
.Visible = True
end with
Set objDoc= objWord.Documents.Add( , ,1, True)
'Office XP
case "10.0"
with objWord
.windowstate = 2
.Visible = False
end with
Set objDoc= objWord.Documents.Add( , ,1, True)
with objWord
.windowstate =2
.Visible = True
end with
'Office 97
case else ' Office 97
Set objDoc= objWord.Documents.Add
end select
objDoc.Content=objSelectRange.text
objDoc.CheckSpelling
strResult = left(objDoc.Content, len(objDoc.Content) - 1)
' This part may not work if you don't use IE
If objSelectRange.text = strResult Then
' There were no spelling errors, so give the user a
' visual signal that something happened
window.alert("The spelling check is complete.")
End If
' Replace the selected text with the corrected text
objSelectRange.text = strResult
'Clean up
objDoc.Close False
Set objDoc= Nothing
objWord.Application.Quit True
Set objWord= Nothing
end if
</SCRIPT>
-
Mar 27th, 2004, 07:54 PM
#2
Hi Martin, not too sure why you're checking the versions there as I think all of the word version support those 3 methods.
I've screwed office up at the moment & have to re-install (why I can't do a sample at the moment), but...
Can you not do a quick app with the enumwindows api & see if the spellcheck window shows up? if it does you should be able to do a GetWindow call then a SetWindowPos call:
VB Code:
Private Const HWND_TOPMOST As Long = -1
Private Const HWND_NOTOPMOST As Long = -2
Private Const SWP_NOSIZE As Long = &H1
Private Const SWP_NOMOVE As Long = &H2
Private Const SWP_NOACTIVATE As Long = &H10
Private Const SWP_SHOWWINDOW As Long = &H40
Private Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Long, _
ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, _
ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
Private Sub Form_Activate()
SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, _
SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
End Sub
-
Mar 27th, 2004, 08:43 PM
#3
Is that stuff supported in VB Script?
-
Mar 28th, 2004, 04:40 AM
#4
ah, ahem - I completely forgot about that one sorry Martin!!!!
I would guess your only option then is to code that part in a separate exe or dll file, then call on this from your vb script.
-
Mar 28th, 2004, 11:19 AM
#5
Through some web research and some basically blind experimentation I've found that I can add the following
Dim dlg
Set dlg = objWord.Dialogs
And once having done that I can replace
objDoc.CheckSpelling
with
dlg(828).Show
or
dlg(828).Show(0)
So far that merely duplicates the original situation but maybe there is some way using the Dialogs approach that will allow for more control over how the window is displayed.
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
|