#1
|
|||
|
|||
Help with a complicated search macro
Hello! I do transcription work where I write long documents with long question/answer segments. The bulk of it is written in a Q&A Style made for these documents, where attorney and witness talk back and forth. Sometimes an interruption happens which is written using the Colloquy Style format, until it later returns to questioning. So for example, it might look like the following.
Code:
Q Good morning, Mr. Doe. A Good morning. Q When did -- hold on. I'm getting ahead of myself. Would you please state your full name for the record? A John Doe. Q When did you hurt your left leg? MR. ATTORNEY: Objection. Vague. I've been able to use .Find code blocks to search and replace other things, and I can successfully find a line using .Text = "Q" & Chr(9), but I don't know how to extend it for conditional checks like this. If I were to write out my goals in pseudocode, it would be something along these lines. Code:
* Search for "Q tab" * Search for the next newline character, Chr(10) * Is first character in the next line "Q tab" again? - if so, HIGHLIGHT IT. - if it's not, AND it's not "A tab", AND it's still in Q&A style, - search for the next newline character again and repeat. (accounts for multiple paragraphs within a single Q or A) - else, we're done here. We found that this "Q tab" is followed by an "A tab". * Continue for the rest of the document. Any help I could get towards this would be massively appreciated! |
#2
|
||||
|
||||
This will get you started.
Code:
Sub ShowDups() Dim aPar As Paragraph, sStart As String On Error Resume Next For Each aPar In ActiveDocument.Paragraphs If aPar.Range.Characters(2).Text = vbTab Then If Left(aPar.Range.Text, 2) = Left(aPar.Next.Range.Text, 2) Then aPar.Next.Range.HighlightColorIndex = wdBrightGreen End If End If Next aPar End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
#3
|
|||
|
|||
Thank you!! It works for any quick Q/As back and forth to each other. But it doesn't work if one Q or A is longer and is made up of multiple paragraphs.
If you're able to add functionality to account for that, that would be phenomenal. If not, no worries, you helped a lot, and I'll look closer at it later when I can get around to it. |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
macro to search * | riccardo67 | Word VBA | 7 | 11-02-2018 07:43 AM |
Complicated (to me) TOC | andydavis | Word | 4 | 10-23-2017 02:06 PM |
Complicated Macro - Capture from Excel | sahrens1 | Word VBA | 2 | 06-25-2017 09:47 AM |
Macro on Search and Replace | davidhuy | Word VBA | 1 | 12-19-2014 04:47 AM |
help with complicated formula | flyinghigher2011 | Excel | 6 | 07-30-2013 02:16 PM |