Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata
Sub SpellCheckDoc()

Dim lockedFields As Long
Dim unlockedFields As New Collection
For Each theFields In ActiveDocument.Fields
    If theFields.Locked = False Then
        unlockedFields.Add theFields
    End If
Next theFields

'Word
Dim objWord As Object
Set objWord = GetObject(, "Word.Application")

'Excel
Dim objExcel As Object, objWB As Object
Set objExcel = CreateObject("Excel.Application")
Set objWB = objExcel.Workbooks.Add
objExcel.Visible = True
Set wb = objExcel.ActiveWorkbook
Set ws = wb.Worksheets("Sheet1")

For Each theFields In unlockedFields
    If CheckSpelling(theFields.Result.Text) = False Then
      theFields.Copy ' Select text from Word Doc

'Paste into new workbook and spellcheck
Dim correctSpelling As String
With ws
 .Range("A1").Select
 .Paste
 .Range("A1").CheckSpelling
 correctSpelling = .Range("A1").Text
End With

theFields.Result.Text = correctSpelling
  
End If
Next theFields

With objExcel.Application
 .DisplayAlerts = False
 .Quit
 .DisplayAlerts = True
End With

End Sub

  • No labels