none
How to ignore blank paragraph characters when running the macro RRS feed

  • Question

  • Hi,

    I've an existing macro to identify font sizes and given Word comment for each. Please see below sample code:

    Private Sub Test()
    Application.ScreenUpdating = False
    Dim oPar As Paragraph
    Dim oRng As Word.Range
    Const message As String = "Check!"
    For Each oPar In ActiveDocument.Paragraphs
    Set oRng = oPar.Range
        With oRng
            With .Find
                .ClearFormatting
                .Text = ""
                .Execute
            End With
            If oPar.Range.Information(wdWithInTable) = False Then
            If oPar.Range.Font.Size <> 10 Then
                .Select
                 Selection.Comments.Add Range:=Selection.Range
                 Selection.TypeText Text:=message
            End If
            End If
          End With
        Next
    Application.ScreenUpdating = True
    End Sub
    

    I've to ignore adding comments on empty paragraph characters to improve macro running speed. Is there any way for that?

    Thanks!


    .

    Wednesday, August 17, 2016 12:58 PM

Answers

  • Hi Sam1085,

    I modified your above mentioned code and now it will not add comment to empty paragraph.

    Private Sub Test()
    Application.ScreenUpdating = False
    Dim oPar As Paragraph
    Dim oRng As Word.Range
    Const message As String = "Check!"
    For Each oPar In ActiveDocument.Paragraphs
    If oPar.Range.Characters.Count = 1 Then
    Else
    Set oRng = oPar.Range
        
        With oRng
            With .Find
                .ClearFormatting
                .Text = ""
                .Execute
            End With
            If oPar.Range.Information(wdWithInTable) = False Then
            If oPar.Range.Font.Size <> 10 Then
                .Select
                 Selection.Comments.Add Range:=Selection.Range
                 Selection.TypeText Text:=message
            End If
            End If
          End With
    End If
        Next
    Application.ScreenUpdating = True
    End Sub

    you will get output like below.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Sam1085 Thursday, August 18, 2016 1:07 AM
    Thursday, August 18, 2016 1:04 AM
    Moderator

All replies

  • How about specifying all the requirements up-front, in a single thread. Your piecemeal approach is merely creating more work for all concerned.

    Cheers
    Paul Edstein
    [MS MVP - Word]

    Wednesday, August 17, 2016 1:02 PM
  • Hi Sam1085,

    I modified your above mentioned code and now it will not add comment to empty paragraph.

    Private Sub Test()
    Application.ScreenUpdating = False
    Dim oPar As Paragraph
    Dim oRng As Word.Range
    Const message As String = "Check!"
    For Each oPar In ActiveDocument.Paragraphs
    If oPar.Range.Characters.Count = 1 Then
    Else
    Set oRng = oPar.Range
        
        With oRng
            With .Find
                .ClearFormatting
                .Text = ""
                .Execute
            End With
            If oPar.Range.Information(wdWithInTable) = False Then
            If oPar.Range.Font.Size <> 10 Then
                .Select
                 Selection.Comments.Add Range:=Selection.Range
                 Selection.TypeText Text:=message
            End If
            End If
          End With
    End If
        Next
    Application.ScreenUpdating = True
    End Sub

    you will get output like below.

    Regards

    Deepak


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Sam1085 Thursday, August 18, 2016 1:07 AM
    Thursday, August 18, 2016 1:04 AM
    Moderator
  • Thanks Deepak,

    It's works perfectly!


    .

    Thursday, August 18, 2016 1:08 AM