|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
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! |
#2
|
||||
|
||||
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 |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
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 |
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 |
Question and answer cards | bobson | Word | 1 | 07-31-2013 10:28 AM |