Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 04-10-2024, 07:11 PM
Guessed's Avatar
Guessed Guessed is offline Text Insert Windows 10 Text Insert Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 4,158
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
Reply With Quote
 

Tags
text insert



Similar Threads
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

Other Forums: Access Forums

All times are GMT -7. The time now is 03:14 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