none
Develop an existing macro to ignore tables RRS feed

  • Question

  • Hi,

    I've a macro to find bold paragraphs and add Word comment for each. And also I've to ignore tables when find the bold paragraphs. Please see below code example for more info:

    Sub Test()
    Application.ScreenUpdating = False
    Const message As String = "Comment!"
    Dim oPar As Paragraph
    Dim oRng As Word.Range
    
    For Each oPar In ActiveDocument.Paragraphs
    Set oRng = oPar.Range
        With oRng
            With .Find
                .ClearFormatting
                .Text = "^13"
                .Wrap = wdFindContinue
                .Format = True
                .Font.Bold = True
                .Execute
            End With
            If oPar.Range.Bold = True Then
                If oPar.Range.Tables = False Then
                     .Select
                      oRng.Comments.Add Range:=oRng
                      Selection.TypeText Text:=message
                      Set oRng = Nothing
                End If
            End If
        End With
        Next
    End Sub

    I've tried to ignore tables by using //If oPar.Range.Tables = False//. But it's not works for me. How do I do that?

    Any inputs would be much appreciated.


    .

    Monday, August 15, 2016 12:26 PM

Answers

  • Instead of

                If oPar.Range.Tables = False Then

    use

                If oPar.Range.Information(wdWithInTable) = False Then


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by Sam1085 Monday, August 15, 2016 2:06 PM
    Monday, August 15, 2016 1:49 PM

All replies

  • Instead of

                If oPar.Range.Tables = False Then

    use

                If oPar.Range.Information(wdWithInTable) = False Then


    Regards, Hans Vogelaar (http://www.eileenslounge.com)

    • Marked as answer by Sam1085 Monday, August 15, 2016 2:06 PM
    Monday, August 15, 2016 1:49 PM
  • Thanks. It's Works!

    .

    Monday, August 15, 2016 2:07 PM