Results 1 to 2 of 2

Thread: Microsoft Word automation

Threaded View

  1. #1

    Thread Starter
    Member docHoliday's Avatar
    Join Date
    Sep 1999
    Location
    Stamford, CT, USA
    Posts
    48

    Microsoft Word automation

    Hey Gang,

    I've been using a nifty bit of code to incorporate Word's spell checker into my program and it works great with Word95 and 97, but I'm starting to receive automation errors with Word2000. I'm not familiar with the major changes in Word2000 as far as automating tasks goes, so if anyone has any suggestions and/or code ideas to help fix this error, I'd be very appreciative. Also, if anyone has been playing with OfficeXP, I'd really like to prepare the code for either automating with that version, or at least ignoring it until which time I can figure out it's automation scheme. Thanks in advance.

    WORD SPELL CHECK AUTOMATION CODE:
    Code:
    Private Function FN_SpellCheck(strTextToVerify As String) As Boolean
    On Error GoTo FN_SpellCheckErr
    
    Dim oWord As Object
    Dim strSelection As String
    Set oWord = CreateObject("Word.Basic")
    With oWord
      .AppMinimize
      .FileNewDefault
      .EditSelectAll
      ' done immediately before to minimize possibility of user
      ' interaction with the clipboard
      Clipboard.Clear
      Clipboard.SetText strTextToVerify, vbCFText
      .EditPaste
      .StartOfDocument
      On Error Resume Next
      .ToolsSpelling
      On Error GoTo 0
      .EditSelectAll
      .EditCOPY
      strSelection = Clipboard.GetText(vbCFText)
      If Mid(strSelection, Len(strSelection), 1) = Chr(13) Then
        strSelection = Mid(strSelection, 1, Len(strSelection) - 1)
      End If
    
      If Len(strSelection) > 1 Then
        strTextToVerify = strSelection
        FN_SpellCheck = True
      End If
      
      .FileCloseAll 2
      .AppClose
    End With
    Set oWord = Nothing
    
    txtFile.Text = strSelection
    MsgBox ("Spell Check is complete"), vbInformation
    Exit Function
    
    FN_SpellCheckErr:
        MsgBox ("SpineText encountered the following error while attempting to spell check your file" _
        & ", Error #" & Err.Number & " " & Err.Description), vbExclamation
        Exit Function
    End Function
    When the form loads, I use this function to test for Word:
    Code:
    If IsAppPresent("Word.Document\CurVer", "") Then
    End If
    
    Public Function IsAppPresent(strSubKey$, strValueName$) As Boolean
    IsAppPresent = CBool(Len(GetRegString(HKEY_CLASSES_ROOT, strSubKey, strValueName)))
    End Function
    Last edited by docHoliday; May 24th, 2001 at 10:30 PM.
    "A balm? That's a dangerous animal. Throw it in the trough!"
    - Monty Python

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