Results 1 to 9 of 9

Thread: Finding string in Word, searching for it in Excel column - if found, replace in Word

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    May 2015
    Posts
    30
    Location
    Because of your help with my previous posts I already did wrote few very simple macros for this project of mine - and did some other work thanks to previous posts. I of course intend to continue learning VBA. I am beginner to this, but I am already better then few months before, all thanks to your posts and me trying to applicate them
    I absolutely understand that good people put their time and energy replying my posts, writing code...and they dont have to.. - so again big thanks for your help and in the future I will try harder on my own.
    Your code above works perfectly.

  2. #2
    VBAX Regular
    Joined
    May 2015
    Posts
    30
    Location

    Smile

    I need to ask for help: I now have document with multiple tables in it and I am using this solution which is very far from elegant : I Just changed the first line of code with .Tables(1) then .Tables(2) .Tables(3) etc ..

    For Each oCell In ActiveDocument.Tables(1).Range.Cells
            Set oRng = oCell.Range
            With oRng.Find
                .Font.ColorIndex = wdRed
                .MatchWildcards = True
                If .Execute Then
                    For lngIndex = 0 To UBound(m_arrExcelContent, 2)
                        If InStr(m_arrExcelContent(0, lngIndex), Trim(oRng.Text)) > 0 Then
                            With oCell
                                .Range.Text = m_arrExcelContent(0, lngIndex)
                                .Range.Font.ColorIndex = wdAuto
                            End With
                            Exit For
                        End If
                    Next
                End If
            End With
        Next
        
        For Each oCell In ActiveDocument.Tables(2).Range.Cells
            Set oRng = oCell.Range
            With oRng.Find
                .Font.ColorIndex = wdRed
                .MatchWildcards = True
                If .Execute Then
                    For lngIndex = 0 To UBound(m_arrExcelContent, 2)
                        If InStr(m_arrExcelContent(0, lngIndex), Trim(oRng.Text)) > 0 Then
                            With oCell
                                .Range.Text = m_arrExcelContent(0, lngIndex)
                                .Range.Font.ColorIndex = wdAuto
                            End With
                            Exit For
                        End If
                    Next
                End If
            End With
        Next
    
    
    ...
    Is there an easy way to edit macro so it would go through every table in document? Thank you guys

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •