How to Quickly Find One-sentence Paragraphs in Your Word Document

In this post, we want to exhibit you the quick way to find all one-sentence paragraphs in your Word document via VBA.

Now and then, some documents can have very specific requirements for their formatting and structures. For instance, you may not be allowed to have paragraphs with just one sentence. These paragraphs are not hard to recognize, but it takes time, especially it’s a long document.

Today, we will offer you the fast way to specify all one-sentence paragraphs in your document.Find One-sentence Paragraphs in Your Word Document

Find All One-sentence Paragraphs in One Document

  1. Firstly, Word counts a period as a sentence. So if there are words such as “Mr.” or “Ms.”, Word considers it as a sentence. To exclude such a distraction, you need to replace “Mr.” with “Mr”. And when finish find paragraph of single sentence, you can change them back. To replace words, you can refer to this link: How to Find and Replace Multiple Items in Your Word Document
  2. Second, press “Alt+ F11” to trigger VBA editor.
  3. Then click “Normal” project.
  4. Click “Insert” tab on the menu bar and choose “Module” on its drop-down menu.Click "Normal"->Click "Insert"->Click "Module"
  5. Next double click on module to open it.
  6. Paste following codes on the module:
Sub HighlightParagraphsWithSingleSentence()
  Dim nParagraphNum As Integer
  Dim nCountParagraph As Integer
  Dim objParagraphRange As Range
  Dim nCountSentence As Integer
  Dim nHighlightNum As Integer
 
  nCountParagraph = ActiveDocument.Paragraphs.Count
  nHighlightNum = 0
 
  For nParagraphNum = 1 To nCountParagraph
    Set objParagraphRange = ActiveDocument.Paragraphs(nParagraphNum).Range
    nCountSentence = objParagraphRange.Sentences.Count
    ' Highlight all paragraphs with single-sentence.
    If nCountSentence = 1 And objParagraphRange.Characters.Count > 1 Then
      nHighlightNum = nHighlightNum + 1
      objParagraphRange.HighlightColorIndex = wdYellow
    End If
  Next

  If nHighlightNum > 0 Then
    MsgBox ("There are " & nHighlightNum & " paragraphs with single sentence and they are highlighted.")
  Else
    MsgBox ("There are no paragraphs with single sentence")
  End If

End Sub
  1. Last but not the least, click “Run” button or hit “F5”.Paste Macro->Click "Run"

You will receive such a message box, telling you the job is done.Highlight One-sentence Paragraphs

Find All One-sentence Paragraphs in Multiple Documents

  1. To begin with, you have to put all target documents in a folder.
  2. Then install and run bellowing macro:
Sub HighlightParagraphsWithSingleSentenceInMultipleFiles()
  Dim nParagraphNum As Integer
  Dim nCountParagraph As Integer
  Dim objParagraphRange As Range
  Dim nCountSentence As Integer
  Dim StrFolder As String
  Dim strFile As String
  Dim objDoc As Document
  Dim dlgFile As FileDialog
  Dim nHighlightNum As Integer
  Dim strSummary As String

  Set dlgFile = Application.FileDialog(msoFileDialogFolderPicker)

  With dlgFile
    If .Show = -1 Then
      StrFolder = .SelectedItems(1) & "\"
    Else
      MsgBox ("No Folder is selected!")
      Exit Sub
    End If
  End With
 
  strFile = Dir(StrFolder & "*.doc*", vbNormal)
 
  While strFile <> ""
    nHighlightNum = 0
    Set objDoc = Documents.Open(FileName:=StrFolder & strFile)
    Set objDoc = ActiveDocument
    nCountParagraph = ActiveDocument.Paragraphs.Count
 
    For nParagraphNum = 1 To nCountParagraph
      Set objParagraphRange = ActiveDocument.Paragraphs(nParagraphNum).Range
      nCountSentence = objParagraphRange.Sentences.Count
      ' Highlight all paragraphs with single-sentence.
      If nCountSentence = 1 And objParagraphRange.Characters.Count > 1 Then
        nHighlightNum = nHighlightNum + 1
        objParagraphRange.HighlightColorIndex = wdYellow
      End If
    Next
    objDoc.ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
    objDoc.Save
    If nHighlightNum = 0 Then
      objDoc.Close
    End If
 
    strSummary = strSummary & strFile & " : " & nHighlightNum & " paragraphs with single sentence." & vbCrLf
    strFile = Dir()
  Wend
  MsgBox (strSummary)
 
End Sub
  1. In the “Browse” window open, pick the folder where you keep documents and click “OK”.Choose a Folder->Click "OK"

The macro then will highlight all one-sentence paragraphs and leave documents open. If a document doesn’t contain a one-sentence paragraph, it will be closed. Besides, there is a message box, indicating the number of one-sentence paragraphs in each document.Result Message

Deal with Data Loss Incident

User errors and sudden power outage can result in the dead of Word. While a collapsed Word can not only affect daily work, but also lead to doc damage. This is by no means the most irritating part of a data disaster. It’s better to get a repairing utility to recover data immediately.

Author Introduction:

Vera Chen is a data recovery expert in DataNumen, Inc., which is the world leader in data recovery technologies, including recover excel and pdf repair software products. For more information visit www.datanumen.com

2 responses to “How to Quickly Find One-sentence Paragraphs in Your Word Document”

  1. Wow, awesome weblog structure! How long have you been running a blog for?
    you make running a blog glance easy. The full look of your web site is excellent, as well as the content
    material! You can see similar here ecommerce

  2. Czy ustalenie planu spłaty kończy postępowanie upadłościowe?

    Hey there! I just wanted to ask if you ever have any issues with hackers?
    My last blog (wordpress) was hacked and I ended up losing a
    few months of hard work due to no backup. Do you have any solutions to stop hackers?
    Jak sprawdzić czy dłużnik ogłosił upadłość?

Leave a Reply

Your email address will not be published. Required fields are marked *