View Single Post
 
Old 05-11-2023, 09:59 PM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,106
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 of
Default

If there are only alternate questions and answers in the text and each answer has only one paragraph then the following macro will do the job. Create a new blank document from your template and paste the text into it, then run the macro. If the text does not fit these criteria then it gets a lot more complicated:
Code:
Sub Macro1()
Dim oRng As Range
Dim oPara As Paragraph
Dim i As Long
    For Each oPara In ActiveDocument.Paragraphs
        Set oRng = oPara.Range
        oRng.End = oRng.End - 1
        If Len(oRng) = 0 Then oPara.Range.Delete
    Next oPara
    For i = 1 To ActiveDocument.Paragraphs.Count
        Set oRng = ActiveDocument.Paragraphs(i).Range
        oRng.Text = Trim(Split(oRng.Text, ":")(1))
        If i Mod 2 = 0 Then
            oRng.Style = "Answer"
        Else
            oRng.Style = "Question"
        End If
    Next i
    Set oRng = Nothing
    Set oPara = 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