Microsoft Word Proof Reading VBA (Visual Basic for Applications)

Microsoft Word Proof Reading VBA (Visual Basic for Applications)

ProofReadingErrors

A collection of spelling and grammatical errors for the specified Document or Range which can be used to perform Proof Reading in a Microsoft Word Document. It offers two main properties which refers to collection:

Properties

  1. SpellingErrors
  2. GrammaticalErrors

Spelling Error

Code example

Public Sub SpellingErrorProofReading()
    
	'Declare range variable
    Dim oRange As Range
    
	'Bind selection to range
    Set oRange = Selection.Range
    
    'Iterate spelling errors
    For Each oError In oRange.SpellingErrors
        MsgBox "Please correct the spelling of " & oError.Text
    Next oError
	
	'Memory cleanup
	Set oRange=Nothing
End Sub

Output

Grammatical Error

Code example

Public Sub GrammaticalErrorsProofReading()
    'Declare range variable
    Dim oRange As Range
    
	'Bind selection to range
    Set oRange = Selection.Range
    
    'Iterate each grammatical error
    For Each oError In oRange.GrammaticalErrors
        
		'Take error into range object
        Dim errRange As Range
        Set errRange = oError
        
        'bold
        errRange.Bold = True
		
        'color text
        errRange.Font.ColorIndex = wdDarkRed
    Next oError
	
	'Memory Cleanup
	set oRange = Nothing
End Sub

Count Property

Public Sub CountErrorProofReadingExample()
    'Declare range variable
    Dim oRange As Range
    
	'Bind selection to range
    Set oRange = Selection.Range
    
    'Display Spelling errors
    MsgBox "Total spelling errors found: " & oRange.SpellingErrors.Count
	
    'Display Grammatical errors
    MsgBox "Total Grammatical errors found: " & oRange.GrammaticalErrors.Count
    
    'Memory cleanup
    Set oRange = Nothing
	
End Sub

Please leave your comments or queries under comment section also please do subscribe to out blogs to keep your self upto date.

Leave a Reply

Your email address will not be published.