View Single Post
 
Old 12-27-2020, 09:37 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 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 works with your example:


Code:
Sub ExtractQuestions()
'Graham Mayor - https://www.gmayor.com - Last updated - 28 Dec 2020
Dim oDoc As Document, oTarget As Document
Dim oRng As Range
Dim sQuestion As String
    Set oDoc = ActiveDocument
    Set oTarget = Documents.Add
    Set oRng = oDoc.Range
    With oRng.Find
        Do While .Execute(findText:=Chr(63))
            sQuestion = oRng.Sentences(1).Text
            sQuestion = Replace(sQuestion, Chr(63), "")    'eliminate question mark
            sQuestion = Replace(sQuestion, Chr(147), "")    'eliminate opening smart quote
            sQuestion = Replace(sQuestion, Chr(148), "")    'eliminate closing smart quote
            sQuestion = Replace(sQuestion, Chr(13), "")    'eliminate paragraph break
            oTarget.Range.InsertAfter sQuestion & vbCr    ' write to new document
            oRng.Collapse 0
        Loop
    End With
lbl_Exit:
    Set oRng = Nothing
    Set oDoc = Nothing
    Set oTarget = Nothing
    Exit Sub
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