![]() |
#2
|
||||
|
||||
![]()
Without access to the text the following should work - at least it does with your example.
Basically it looks for the " | " string which separates the similar texts, then identifies the next word, then deletes all the previous words until the identified next word is found. It then deletes the previous word (which is the repeated identified word) and then sets the found string to a single space before looking for the next " | " string. A big problem is that what Word sees as a 'word' may not be what you think of as a 'word' and punctuation in the strings can screw it all up. Code:
Sub Macro1() Dim orng As Range Dim orngA As Range On Error GoTo err_Handler Set orng = ActiveDocument.Range With orng.Find Do While .Execute(FindText:=" | ") Set orngA = orng.Next.Words.First Do Until orng.Previous.Words.Last = orngA orng.Previous.Words.Last.Delete Loop orng.Previous.Words.Last.Delete orng.Text = " " orng.Collapse 0 Loop End With lbl_Exit: Set orng = Nothing Set orngA = Nothing Exit Sub err_Handler: Err.Clear GoTo lbl_Exit End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
dyb | Word VBA | 5 | 02-17-2022 01:43 AM |
![]() |
Cov_ATC | Word VBA | 10 | 11-28-2021 03:41 PM |
Word Sections - Bookmarks | ldoodle | Word VBA | 3 | 11-07-2018 07:04 AM |
Word is switching sections upon printing/PDF | rlockwood | Word | 0 | 01-08-2018 09:23 AM |
Word 2007 - how to manage sections? | JQP | Word | 2 | 10-10-2011 11:06 AM |