Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 09-24-2019, 08:50 PM
gmayor's Avatar
gmayor gmayor is offline Extracting Specific Text Strings Windows 10 Extracting Specific Text Strings 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

The following will write sentences containing 'the supplier', regardless of case, to a new document.
Code:
Sub Macro1()
'Graham Mayor - https://www.gmayor.com - Last updated - 25 Sep 2019
Dim oSource As Document
Dim oTarget As Document
Dim oRng As Range, oTargetRng As Range
    Set oSource = ActiveDocument
    Set oTarget = Documents.Add
    Set oRng = oSource.Range
    With oRng.Find
        Do While .Execute(findText:="the supplier")
            oRng.Start = oRng.Sentences(1).Start
            oRng.End = oRng.Sentences(1).End
            Set oTargetRng = oTarget.Range
            oTargetRng.Collapse 0
            oTargetRng.FormattedText = oRng.FormattedText
            oRng.Collapse 0
        Loop
    End With
    Set oRng = Nothing
    Set oTargetRng = Nothing
    Set oSource = Nothing
    Set oTarget = Nothing
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
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extracting Specific Text Strings Renaming several strings of text by their pattern noname91 Word 10 01-05-2017 05:46 PM
Extracting lines containing specific word. S.Allen Word VBA 1 03-27-2015 10:50 PM
Extracting specific rows sbdk82 Excel 4 09-07-2014 10:24 PM
Extracting Specific Text Strings Need help extracting specific text from one doument to another with macro/VBA. zsmithku Word 1 04-15-2011 03:46 PM
Extracting Specific Text Strings update style of all strings available between two specific strings vikrantkale Word 1 03-28-2011 06:13 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:53 PM.


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