![]() |
#2
|
||||
|
||||
![]()
Rather than looping through every table, I would use the Find command along the following lines.
Code:
Sub TableTags() Dim str As String, aRng As Range, sPrefix() As String, i As Integer Dim insertTextAbove() As String, insertTextBelow() As String sPrefix = Split("B|E|I", "|") insertTextAbove = Split("123|456|789", "|") insertTextBelow = Split("333|666|999", "|") For i = LBound(sPrefix) To UBound(sPrefix) Set aRng = ActiveDocument.Range With aRng.Find .Forward = True .Text = sPrefix(i) & "BEGINING" If .Execute Then If aRng.Information(wdWithInTable) Then Set aRng = aRng.Tables(1).Range aRng.Collapse Direction:=wdCollapseStart aRng.MoveStart Unit:=wdCharacter, Count:=-1 aRng.InsertBefore vbCrLf & insertTextAbove(i) GoTo NextOne End If End If End With NextOne: Next i For i = LBound(sPrefix) To UBound(sPrefix) Set aRng = ActiveDocument.Range With aRng.Find .Forward = False .Text = sPrefix(i) & "ENDING" If .Execute Then If aRng.Information(wdWithInTable) Then Set aRng = aRng.Tables(1).Range aRng.Collapse Direction:=wdCollapseEnd 'aRng.MoveEnd Unit:=wdCharacter, Count:=1 aRng.InsertAfter insertTextBelow(i) & vbCrLf GoTo NextTwo End If End If End With NextTwo: Next i End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
Tags |
text insert |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Insert text box | otuatail | Word | 2 | 11-13-2022 08:33 AM |
VBA Word - Find Text Font Color - Insert New Text | jc491 | Word VBA | 2 | 01-04-2016 05:42 PM |
VBA Search Table for Text/Select Text/Insert Hyperlink | sldrellich | Word VBA | 3 | 03-24-2015 01:09 PM |
Insert a text conditionally | deboer | Word | 1 | 05-04-2014 03:35 PM |
Macro to insert Text | Morte | Excel Programming | 1 | 03-04-2014 04:33 PM |