VBA Code


    With Application.AutoCorrect 
        .DisplayAutoCorrectOptions = True
        .TwoInitialCapitals = True
        .CorrectSentenceCap = True
        .CapitalizeNamesOfDays = True
        .CorrectCapsLock = True
        .ReplaceText = True
    End With


Highlight any misspelled words, so that unrecognized words stand out prominently on a printout


Sub HighlightMisspelledWords() 
Dim oWord As Range
Dim StoryRange As Range
For Each StoryRange In ActiveDocument.StoryRanges
    Application.CheckSpelling Word:=StoryRange
    For Each oWord In StoryRange.Words
        If Not Application.CheckSpelling(Word:=oWord.Text) Then
            oWord.HighlightColorIndex = wdColorIndex.wdYellow
        End If
    Next oWord
Next StoryRange
End Sub

The following macro clears highlighting from all words:

Sub ClearHighlightFromAllWords() 
Dim StoryRange As Range
For Each StoryRange In ActiveDocument.StoryRanges
    StoryRange.HighlightColorIndex = wdColorIndex.wdNoHighlight
Next StoryRange
End Sub

Application.Options.AutoFormatApplyBulletedLists 
Application.Options.AutoFormatApplyFirstIndents
Application.Options.AutoFormatApplyHeadings
Application.Options.AutoFormatApplyLists
Application.Options.AutoFormatApplyOtherParas
Application.Options.AutoFormatAsYouTypeApplyBorders
Application.Options.AutoFormatAsYouTypeApplyBulletedLists
Application.Options.AutoFormatAsYouTypeApplyClosings
Application.Options.AutoFormatAsYouTypeApplyDates
Application.Options.AutoFormatAsYouTypeApplyFirstIndents
Application.Options.AutoFormatAsYouTypeApplyHeadings
Application.Options.AutoFormatAsYouTypeApplyNumberedLists
Application.Options.AutoFormatAsYouTypeApplyTables
Application.Options.AutoFormatAsYouTypeAutoLetterWizard
Application.Options.AutoFormatAsYouTypeDefineStyles
Application.Options.AutoFormatAsYouTypeDeleteAutoSpaces
Application.Options.AutoFormatAsYouTypeFormatListItemBeginning
Application.Options.AutoFormatAsYouTypeInsertClosings
Application.Options.AutoFormatAsYouTypeInsertOvers
Application.Options.AutoFormatAsYouTypeMatchParentheses
Application.Options.AutoFormatAsYouTypeReplaceFarEastDashes
Application.Options.AutoFormatAsYouTypeReplaceFractions
Application.Options.AutoFormatAsYouTypeReplaceHyperlinks
Application.Options.AutoFormatAsYouTypeReplaceOrdinals
Application.Options.AutoFormatAsYouTypeReplacePlainTextEmphasis
Application.Options.AutoFormatAsYouTypeReplaceQuotes
Application.Options.AutoFormatAsYouTypeReplaceSymbols
Application.Options.AutoFormatDeleteAutoSpaces
Application.Options.AutoFormatMatchParentheses
Application.Options.AutoFormatPlainTextWordMail
Application.Options.AutoFormatPreserveStyles
Application.Options.AutoFormatReplaceFarEastDashes
Application.Options.AutoFormatReplaceFractions
Application.Options.AutoFormatReplaceHyperlinks
Application.Options.AutoFormatReplaceOrdinals
Application.Options.AutoFormatReplacePlainTextEmphasis
Application.Options.AutoFormatReplaceQuotes
Application.Options.AutoFormatReplaceSymbols


Begins a spelling and grammar check for the document and displays the spelling and grammar dialog box when an error occurs.

objDocument.CheckGrammar 

If objDocument.GrammarChecked = True / False 

selection.range.checkspelling 


Begins a spell check. Once this has been executed the SpellingChecked property is set to true
Any subsequent calls will not work unless this property has been set to False.

objDocument.CheckSpelling 


The SpellingErrors property returns the ProofReadingErrors collection which contains Range objects that identify the words in the document that are considered to be spelling mistakes.

Set objProofReadingErrors = ActiveDocument.SpellingErrors 

The ResetIgnoreAll method clears the list of words that were set to be ignored during the previous spell check.
After this method has been executed all previously ignored words are included in the spell check.

Application.ResetIgnoreAll 


objDocument.ComputeStatistics wdStatistic.wdStatisticWords, includefootersandendnotes 

The word count is displayed

Set myStat = ActiveDocument.ReadabilityStatistics 
Msgbox myStat(1).Name & " - " & myStat(1).Value


Toggle the wavy lines

With ActiveDocument 
   If .ShowGrammaticalErrors = True Then
      .ShowSpellingErrors = False
      .ShowGrammaticalErrors = False
   Else
      If
         .ShowSpellingErrors = False
         .ShowGrammaticalErrors = False
      Else
         .ShowSpellingErrors = True
         .ShowGrammaticalErrors = True
      End If
   End If
End With


Print Spelling Errors

Performing a spell check can sometimes take a long time so it is advisable to use the status bar.


Public Sub printSpellingErrors 
Dim doc As Document
Dim pf As ProofreadingErrors
Dim pe As Range
Dim sName As String

   Application.StatusBar = "Checking Spelling. Please wait. Press Ctrl + Break to interrupt>"

   Set pf = ActiveDocument.SpellingErrors
   sName = ActiveDocument.FullName

'adding a new document, makes the new document the active one
   Set doc = Application.Documents.Add
   doc.Range.InsertAfter "Spelling errors for document: " & sName & vbCr
   doc.Range.InsertAfter "Spelling errors count " & pf.Count & vbCr

'loop through all the spelling mistakes
   For Each pe In pf
      doc.Range.InsertAfter "Page " & pe.Information(wdActiveEndAdjustedPageNumber) & " / " & pe.Text & vbCr
   Next pe

   Application.StatusBar = ""

   doc.SaveAs "C:\Temp\Name2.doc"

End Sub


Word Property

Returns the word or phrase that was looked up by the thesaurus. Read-only String.


This example returns a list of synonyms for the first meaning of the third word in the active document.

Sub Syn() 
    Dim mySynObj As Object
    Dim SList As Variant
    Dim i As Variant

    Set mySynObj = ActiveDocument.Words(3).SynonymInfo
    SList = mySynObj.SynonymList(1)
    For i = 1 To UBound(SList)
        MsgBox "A synonym for " & mySynObj.Word _
            & " is " & SList(i)
    Next i
End Sub

This example checks to make sure that the word or phrase that was looked up isn't empty. If it's not, the example returns a list of synonyms for the first meaning of the word or phrase.

Sub SelectWord() 
    Dim mySynObj As Object
    Dim SList As Variant
    Dim i As Variant

    Set mySynObj = Selection.Range.SynonymInfo
    If mySynObj.Word = "" Then
        MsgBox "Please select a word or phrase"
    Else
        SList = mySynObj.SynonymList(1)
        For i = 1 To UBound(SList)
            MsgBox "A synonym for " & mySynObj.Word _
                & " is " & SList(i)
        Next i
    End If
End Sub



© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrev