Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 01-07-2018, 07:52 AM
gmayor's Avatar
gmayor gmayor is offline "Stitch" word sections together Windows 10 "Stitch" word sections together Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,144
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

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
"Stitch" word sections together Unprotect sections in a word document using VBA dyb Word VBA 5 02-17-2022 01:43 AM
"Stitch" word sections together Word VBA - "Page left Blank" between Sections to make all Sections start on even page 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

Other Forums: Access Forums

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