Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 12-24-2020, 09:37 PM
gmayor's Avatar
gmayor gmayor is offline How can I extract text question between characters Windows 10 How can I extract text question between characters Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,142
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

Looking for text between two very common characters such as '.' and '?' is bound to produce lots of false positives. It is necessary to narrow the search criteria.


In this example I would simply search for the string and remove the unwanted characters e.g.
Code:
Sub Macro1()
Const strFind As String = ". How are you today?"
Dim sText As String
    Selection.HomeKey wdStory
    Selection.Find.ClearFormatting
    With Selection.Find
        Do While .Execute(findText:=strFind, _
                          MatchWildcards:=False, _
                          Wrap:=wdFindStop, _
                          Forward:=True) = True
            sText = Replace(Selection.Range, ". ", "")
            sText = Replace(sText, "?", "")
            'do something with the found text e.g.
            MsgBox sText
        Loop
    End With
lbl_Exit:
    Exit Sub
End Sub
but see Replace using wildcards
__________________
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
 

Tags
vba



Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I extract text question between characters Extract all characters from the nth number of a string Marcia Excel 2 02-24-2020 05:15 PM
How can I extract text question between characters How to extract text between <> LearnerExcel Excel 4 02-07-2018 06:11 AM
Formula to Extract text from a text string Haha88 Excel 2 11-14-2017 01:32 AM
How can I extract text question between characters Extract Line of Text w/ specific characters up to the paragraph character, send to Excel dmarie123 Word VBA 10 07-20-2015 12:16 AM
Macro to find text in between two characters and then format selected text? qcom Word 5 02-19-2015 11:23 PM

Other Forums: Access Forums

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