View Single Post
 
Old 12-15-2018, 10:18 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Undoubtedly by using activedocument rather than the document names you have applied, the code is losing track of which document is which. The folllowing should address it:


Code:
Option Explicit

Private Sub cmdSpellCheck_Click()
    DoSpellCheck TextBox1
    MsgBox "Spelling and Grammar Check Complete"
lbl_Exit:
    Exit Sub
End Sub

Public Sub DoSpellCheck(oTxtBox As Control)
Dim oDoc2 As Document
Dim oRng As Range
    Set oDoc2 = Documents.Add
    With oTxtBox
        If Not .value = "" And Not .value = "<WhatEver>" Then
            Set oRng = oDoc2.Range
            oRng = .value
            With oRng
                .SpellingChecked = False
                .CheckSpelling AlwaysSuggest:=True
                .CheckGrammar
                .End = .End - 1
            End With
            'Return data to the Userform
            .value = oRng.Text
            oDoc2.Close SaveChanges:=wdDoNotSaveChanges
        End If
    End With
    Set oDoc2 = Nothing
    Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote