View Single Post
 
Old 02-24-2016, 10:05 PM
PRA007's Avatar
PRA007 PRA007 is offline Windows 7 64bit Office 2010 32bit
Competent Performer
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default Working with selection.tables

Since I got nice answer at https://www.msofficeforums.com/word-...sing-word.html my life become easier. My every task is based on this template since.

Code:
Sub template()
'From https://www.msofficeforums.com/word-vba/28819-extracting-data-excel-document-using-word.html
Application.ScreenUpdating = False
Set wdDoc = ActiveDocument
With wdDoc.Range
    For Each Tbl In .Tables
        With Tbl
            For i = 1 To .Rows.Count
                With .Cell(i, 2).Range.Paragraphs(1).Range
                    With .Find
                        .ClearFormatting
                        .Replacement.ClearFormatting
                        .Text = "String"
                        .Replacement.Text = ""
                        .Forward = True
                        .Wrap = wdFindStop
                        .Format = False
                        .MatchWildcards = True
                        .Execute
                    End With
                        If .Find.Found Then
							'Do whatever you want.
                        End If
                End With
            Next
        End With
    Next
End With
End Sub
Everything is working fine with template. I made some edits from the answer to make it clear. Now the problem is I tried my best to make the template that is doing exactly similar what above is doing except not for every table but for selected table. (Table no. is not fixed so table with cursor). I tried modifying for each tbl to selection.tables but as you no is not that easy. What is the right way to do that?
Reply With Quote