Results 1 to 5 of 5

Thread: VBScript Spellchecking

  1. #1

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    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:
    1. <!--
    2. +---------------------------------------------------------------------------+
    3.  
    4.     Function:    Spell Checker
    5.     Description: This script uses Microsoft Word to check the spelling in
    6.                  posts. Word is assumed to be present.
    7.  
    8. +---------------------------------------------------------------------------+
    9. -->
    10.  
    11. <SCRIPT LANGUAGE = "VBScript">  
    12.    
    13. Dim objWord
    14. Dim objDoc
    15. Dim objWindow
    16. Dim objSource
    17. Dim objSelect
    18. Dim objSelectRange
    19. Dim strResult
    20.  
    21. Set objWindow = window.external.menuArguments
    22. Set objSource = objWindow.event.srcElement
    23. Set oDocument = objWindow.document
    24. Set objSelect = oDocument.selection
    25. Set objSelectRange = objSelect.createRange()
    26. 'Create a new instance of word Application
    27. Set objWord = CreateObject("word.Application")
    28.  
    29. If objSource.tagName = "TEXTAREA" Then
    30.     select case objWord.version
    31.         'Office 2000
    32.         case "9.0"
    33.             with objWord
    34.                 .WindowState = 2
    35.                 .Visible = True
    36.             end with
    37.             Set objDoc= objWord.Documents.Add( , ,1, True)
    38.         'Office XP
    39.         case "10.0"
    40.             with objWord
    41.                 .windowstate = 2
    42.                 .Visible = False
    43.             end with
    44.             Set objDoc= objWord.Documents.Add( , ,1, True)
    45.             with objWord
    46.                 .windowstate =2
    47.                 .Visible = True
    48.             end with
    49.         'Office 97
    50.         case else ' Office 97
    51.             Set objDoc= objWord.Documents.Add
    52.     end select
    53.  
    54.         objDoc.Content=objSelectRange.text
    55.         objDoc.CheckSpelling
    56.  
    57.     strResult = left(objDoc.Content, len(objDoc.Content) - 1)
    58.  
    59.     ' This part may not work if you don't use IE
    60.     If objSelectRange.text = strResult Then
    61.         ' There were no spelling errors, so give the user a
    62.         ' visual signal that something happened
    63.         window.alert("The spelling check is complete.")
    64.     End If
    65.  
    66.         ' Replace the selected text with the corrected text
    67.     objSelectRange.text = strResult
    68.  
    69.         'Clean up
    70.         objDoc.Close False
    71.         Set objDoc= Nothing
    72.         objWord.Application.Quit True
    73.         Set objWord= Nothing
    74. end if
    75.  
    76. </SCRIPT>

  2. #2
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    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:
    1. Private Const HWND_TOPMOST      As Long = -1
    2. Private Const HWND_NOTOPMOST    As Long = -2
    3. Private Const SWP_NOSIZE        As Long = &H1
    4. Private Const SWP_NOMOVE        As Long = &H2
    5. Private Const SWP_NOACTIVATE    As Long = &H10
    6. Private Const SWP_SHOWWINDOW    As Long = &H40
    7.  
    8. Private Declare Sub SetWindowPos Lib "User32" (ByVal hWnd As Long, _
    9. ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, _
    10. ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long)
    11.  
    12. Private Sub Form_Activate()
    13.     SetWindowPos Me.hWnd, HWND_TOPMOST, 0, 0, 0, 0, _
    14.     SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or SWP_NOSIZE
    15. End Sub

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  3. #3

  4. #4
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    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.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  5. #5

    Thread Starter
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427
    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
  •  



Click Here to Expand Forum to Full Width