Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-11-2023, 03:39 PM
choward choward is offline Take existing Q&A Text And Convert to alternating Question and Answer Styles Windows 11 Take existing Q&A Text And Convert to alternating Question and Answer Styles Office 2021
Novice
Take existing Q&A Text And Convert to alternating Question and Answer Styles
 
Join Date: May 2023
Posts: 1
choward is on a distinguished road
Default Take existing Q&A Text And Convert to alternating Question and Answer Styles

We have a text file that has questions and answers from an interview. The format is below:

Speaker 0: Hello

Speaker 1: Hello.

Speaker 0: Question

Speaker 1: Answer

From that text file in that format, we would want to convert that text into an alternating Question Style and Answer Style that we have already created within a word doc template.

A picture of the final version is attached.



Thank you!
Attached Images
File Type: jpg Screenshot 2023-05-11 183229.jpg (65.5 KB, 5 views)
Reply With Quote
  #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,101
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
Reply

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 03:03 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft