Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-24-2016, 10:05 PM
PRA007's Avatar
PRA007 PRA007 is offline Working with selection.tables Windows 7 64bit Working with selection.tables Office 2010 32bit
Competent Performer
Working with selection.tables
 
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
  #2  
Old 02-24-2016, 10:58 PM
gmayor's Avatar
gmayor gmayor is offline Working with selection.tables Windows 10 Working with selection.tables Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Delete the loop and set the table to Selection.Tables(1)
Code:
Dim Tbl as table
Set Tbl = Selection.Tables(1)
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 02-24-2016, 11:36 PM
macropod's Avatar
macropod macropod is offline Working with selection.tables Windows 7 64bit Working with selection.tables Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,369
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Or you could just delete:
Set wdDoc = ActiveDocument
and change:
wdDoc
to:
Selection
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 02-25-2016, 01:49 AM
PRA007's Avatar
PRA007 PRA007 is offline Working with selection.tables Windows 7 64bit Working with selection.tables Office 2010 32bit
Competent Performer
Working with selection.tables
 
Join Date: Dec 2014
Location: Ahmedabad, Gujrat, India
Posts: 145
PRA007 is on a distinguished road
Default

Great. That simple!
Reply With Quote
Reply

Tags
word vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
Working with selection.tables Working with Selection.range. PRA007 Word VBA 2 02-19-2016 12:52 AM
Working with selection.tables Working with word tables. PRA007 Word VBA 1 12-02-2015 04:22 AM
Working with selection.tables Header Rows in Tables Not Working Andy Pilkington Word 2 10-10-2014 12:36 AM
Working with selection.tables Selection.EndKey not working in 2010 Smallweed Word VBA 4 08-19-2014 07:21 AM
Working with selection.tables working with excel tables in MS word radman154 Word Tables 1 03-25-2011 12:04 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 06:48 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft