Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-09-2023, 12:36 PM
Donovahkiin Donovahkiin is offline Help with a complicated search macro Windows 10 Help with a complicated search macro Office 2016
Novice
Help with a complicated search macro
 
Join Date: Oct 2023
Posts: 4
Donovahkiin is on a distinguished road
Question 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'm trying to write a macro that will highlight if there's any times that on consecutive lines I lead it with the wrong speaker token. Meaning, if I have a Q line followed by another Q line or an A line followed by another A line. Each line leads with either Q or A followed by the tab key. The objection doesn't use any tab characters, it just changes to the Colloquy style.

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.
Then I would duplicate and mirror this macro to make another one that checks if there's two A lines in a row.

Any help I could get towards this would be massively appreciated!
Reply With Quote
  #2  
Old 10-09-2023, 05:23 PM
Guessed's Avatar
Guessed Guessed is offline Help with a complicated search macro Windows 10 Help with a complicated search macro Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

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
I put the error resume in because the loop would fail when looking for the paragraph after the last paragraph (and I couldn't be bothered complicating the code to deal with that).
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 10-17-2023, 03:19 PM
Donovahkiin Donovahkiin is offline Help with a complicated search macro Windows 10 Help with a complicated search macro Office 2016
Novice
Help with a complicated search macro
 
Join Date: Oct 2023
Posts: 4
Donovahkiin is on a distinguished road
Default

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.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with a complicated search macro macro to search * riccardo67 Word VBA 7 11-02-2018 07:43 AM
Help with a complicated search macro 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

Other Forums: Access Forums

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