Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 05-11-2023, 09:59 PM
gmayor's Avatar
gmayor gmayor is offline Take existing Q&A Text And Convert to alternating Question and Answer Styles Windows 10 Take existing Q&A Text And Convert to alternating Question and Answer Styles Office 2019
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

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
 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Take existing Q&A Text And Convert to alternating Question and Answer Styles Applying New Multi-Level List to Existing Document with Manual Numbering and Existing Styles stanley Word 4 12-15-2020 10:59 AM
Does a new set of styles in a template overwrite or remove the existing set of styles in a document? dianahbr Word 6 03-27-2018 11:12 PM
Take existing Q&A Text And Convert to alternating Question and Answer Styles Question about multiple fill-in fields with the same answer Blades2002 Word 2 08-31-2015 11:20 AM
Question and answer fill in the form template? ej53 Word 0 04-28-2015 09:12 AM
Take existing Q&A Text And Convert to alternating Question and Answer Styles Question and answer cards bobson Word 1 07-31-2013 10:28 AM

Other Forums: Access Forums

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