Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 02-17-2022, 12:38 AM
ranjan ranjan is offline Replace String Windows 10 Replace String Office 2019
Advanced Beginner
Replace String
 
Join Date: May 2021
Posts: 80
ranjan is on a distinguished road
Default

Only replace a first row in every table and shouldn't get replaced in any where else in a document...

I have tried the below one, can you review the range once.

Range is first row of a every table. (It shouldnt get replaced otherthan a first row of a tables)

Code:
Sub Test_Replace()
Application.ScreenUpdating = False
Dim Rng As Range
With ActiveDocument.Range
  With .Find
    .ClearFormatting
    .Replacement.ClearFormatting
    .Text = "sample"
    .Replacement.Text = "Sample"
    .Format = False
    .Forward = False
    .Wrap = wdFindStop
    .MatchCase = True
    .MatchWholeWord = False
    .MatchWildcards = False
    .Execute Replace:=wdReplaceAll
  End With
  Do While .Find.Execute
    If .Information(wdWithInTable) = True Then
      Set Rng = ActiveDocument.Tables(1).Cell(1, 0)
        Do While Rng.Tables.Count > 0
       Loop
      Exit Do
    End If
    .Collapse wdCollapseStart
  Loop
End With
Application.ScreenUpdating = True
End Sub
Reply With Quote
 

Tags
find, replace



Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I replace string 123-4 with 123 4 davidjm Word VBA 25 11-03-2021 02:40 PM
Replace String Replace characters in a string Marcia Excel Programming 5 05-04-2020 05:15 AM
Replace String Wildcard replace any string in context with a specified string wardw Word 7 05-07-2018 09:13 AM
Replace String Replace characters in a string Anthon Excel Programming 1 11-03-2016 12:48 AM
Replace String Find and replace a string of text errtu Word 1 01-31-2013 02:09 PM

Other Forums: Access Forums

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