Public moApp As Object
Private mbKillMe As Boolean
Public Property Get KillMe() As Boolean
InitializeMe
KillMe = mbKillMe
End Property
Public Property Let KillMe(Value As Boolean)
mbKillMe = Value
End Property
Public Sub InitializeMe()
On Error Resume Next
Set moApp = GetObject(, "Word.Application")
If TypeName(moApp) <> "Nothing" Then
Set moApp = GetObject(, "Word.Application")
Else
Set moApp = CreateObject("Word.Application")
mbKillMe = True
End If
End Sub
Public Function SpellMe(ByVal msSpell As String) As String
On Error GoTo No_Bugs
Dim oDoc As Object 'Word.Document
Dim iWSE As Integer
Dim iWGE As Integer
Dim sReplace As String
Dim lResp As Long
If msSpell = vbNullString Then Exit Function
InitializeMe
Select Case moApp.Version
Case "9.0", "10.0", "11.0"
Set oDoc = moApp.Documents.Add(, , 1, True)
Case "8.0"
Set oDoc = moApp.Documents.Add
Case Else
MsgBox "Unsupported Version of Word.", vbOKOnly + vbExclamation, "VB/Office Guru™ SpellChecker™"
SpellMe = msSpell
Exit Function
End Select
Screen.MousePointer = vbHourglass
App.OleRequestPendingTimeout = 999999
oDoc.Words.First.InsertBefore msSpell
iWSE = oDoc.SpellingErrors.Count
iWGE = oDoc.GrammaticalErrors.Count
If iWSE > 0 Or iWGE > 0 Then
moApp.Assistant.On = False
moApp.Visible = False
If (moApp.WindowState = 0) Or (moApp.WindowState = 1) Then
moApp.WindowState = 2
Else
moApp.WindowState = 2
End If
moApp.Dialogs(828).Application.Options.CheckGrammarWithSpelling = True
moApp.Dialogs(828).Application.Options.SuggestSpellingCorrections = True
moApp.Dialogs(828).Application.Options.IgnoreUppercase = True
moApp.Dialogs(828).Application.Options.IgnoreInternetAndFileAddresses = True
moApp.Dialogs(828).Application.Options.IgnoreMixedDigits = False
moApp.Dialogs(828).Application.Options.ShowReadabilityStatistics = False
moApp.Visible = True
moApp.Activate
lResp = moApp.Dialogs(828).Display
If lResp < 0 Then
moApp.Visible = True
MsgBox "Corrections Being Updated!", vbOKOnly + vbInformation, App.ProductName
Clipboard.Clear
oDoc.Select
oDoc.Range.Copy
sReplace = Clipboard.GetText(1)
If (InStrRev(sReplace, Chr(13) & Chr(10))) = (Len(sReplace) - 1) Then
sReplace = Mid$(sReplace, 1, Len(sReplace) - 2)
End If
SpellMe = sReplace
ElseIf lResp = 0 Then
MsgBox "Spelling Corrections Have Been Canceled!", vbOKOnly + vbCritical, "VB/Office Guru™ SpellChecker"
SpellMe = msSpell
End If
Else
MsgBox "No Spelling Errors Found" & vbNewLine & "Or No Suggestions Available!", vbOKOnly + vbInformation, _
"VB/Office Guru™ SpellChecker"
SpellMe = msSpell
End If
oDoc.Close False
Set oDoc = Nothing
If KillMe = True Then
moApp.Visible = False
End If
Screen.MousePointer = vbNormal
Exit Function
No_Bugs:
If Err.Number = "91" Then
SpellMe = msSpell
Resume Next
ElseIf Err.Number = "462" Then
SpellMe = msSpell
MsgBox "Spell Checking Is Temporary Un-Available!" & vbNewLine & "Make sure an e-mail message is not open.", _
vbInformation, "ActiveX Server Not Responding"
Screen.MousePointer = vbNormal
ElseIf Err.Number = 429 Then
SpellMe = msSpell
Set moApp = Nothing
Resume Next
Else
SpellMe = msSpell
MsgBox Err.Number & " " & Err.Description, vbOKOnly + vbInformation, App.ProductName
Screen.MousePointer = vbNormal
End If
End Function