Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-14-2020, 11:57 AM
snk13 snk13 is offline Highlighting paragraphs based on find results Mac OS X Highlighting paragraphs based on find results Office 2016 for Mac
Novice
Highlighting paragraphs based on find results
 
Join Date: Sep 2020
Posts: 2
snk13 is on a distinguished road
Default Highlighting paragraphs based on find results

Hi everyone. I was hoping someone could help me with a coding challenge. I create test bank questions, and I'm looking for a way to highlight the correct answer option in Word based on what is in the answer field.

For example, in this question, I would want to highlight the paragraph "b. dog" based on the paragraph "Ans: B".

Type: MC
Shuffle: Yes
1. Which animal makes the best pet?
a. lion


b. dog
c. giraffe
d. whale
Ans: B

Does anyone have a recommendation on how to accomplish this?
Thanks!
Reply With Quote
  #2  
Old 09-14-2020, 03:32 PM
Guessed's Avatar
Guessed Guessed is offline Highlighting paragraphs based on find results Windows 10 Highlighting paragraphs based on find results Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,848
Guessed is a glorious beacon of lightGuessed is a glorious beacon of lightGuessed is a glorious beacon of lightGuessed is a glorious beacon of lightGuessed is a glorious beacon of lightGuessed is a glorious beacon of light
Default

You will need to provide an example document which shows EXACTLY what the document will contain. Specifically, we need to see the styles and whether the numbers and letters are automatic lists or manually typed.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 09-16-2020, 08:40 AM
snk13 snk13 is offline Highlighting paragraphs based on find results Mac OS X Highlighting paragraphs based on find results Office 2016 for Mac
Novice
Highlighting paragraphs based on find results
 
Join Date: Sep 2020
Posts: 2
snk13 is on a distinguished road
Default

The above is an exact replication of what is in the Word documents. All text is manually keyed (no autolists), there are no double spaces or tabs in the file, and there is no paragraph styling.

I thought I could search for "Ans: A" and then insert "<ans>" at the start of the line with the a. answer option. Same for answers B, C, and D. I can get that to work, but I'm not clear on how to set up a Do While (or whatever would be appropriate) for this type of work.

Once the "<ans>" tag is applied, I can apply the highlighting.

Thanks!
Reply With Quote
  #4  
Old 09-16-2020, 06:19 PM
Guessed's Avatar
Guessed Guessed is offline Highlighting paragraphs based on find results Windows 10 Highlighting paragraphs based on find results Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 1,848
Guessed is a glorious beacon of lightGuessed is a glorious beacon of lightGuessed is a glorious beacon of lightGuessed is a glorious beacon of lightGuessed is a glorious beacon of lightGuessed is a glorious beacon of light
Default

Here is one approach. It assumes you have an "Answer" style in your document to apply to the correct answers. You can then have a secondary macro that toggles the "Answer" style as being same/different to the Normal style if you wanted to show or hide the answers.
Code:
Sub MarkAnswers()
  Dim lngPara As Long, iOffset As Integer, sAnswer As String
  For lngPara = 1 To ActiveDocument.Paragraphs.Count
    If Left(ActiveDocument.Paragraphs(lngPara).Range.Text, 5) = "Ans: " Then
      sAnswer = ActiveDocument.Paragraphs(lngPara).Range.Words(3)
      iOffset = Asc(sAnswer) - 69
      Debug.Print lngPara, sAnswer, iOffset
      ActiveDocument.Paragraphs(lngPara + iOffset).Range.Style = "Answer"
    End If
  Next lngPara
End Sub

Sub ToggleAnswerShow()
  Dim aSty As Style
  With ActiveDocument.Styles("Answer")
    If .Font.Bold = ActiveDocument.Styles("Normal").Font.Bold Then
      .Font.Bold = True
      .Font.ColorIndex = wdGreen
    Else
      .Font = ActiveDocument.Styles("Normal").Font
    End If
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Highlighting paragraphs based on find results Find/Replace Results in CAPS RKS-P Word 12 09-30-2019 08:26 AM
Highlighting paragraphs based on find results Rolling up monthly results based on weeknum? chollyred Excel 1 08-26-2016 08:20 AM
Highlighting paragraphs based on find results Highlighting Excel FIND Results rstrimel Excel 7 09-10-2014 07:54 AM
Highlighting paragraphs based on find results SUMIF results changed based on filters SteveBump Excel 5 10-29-2013 07:25 AM
Highlighting paragraphs based on find results Copy Row based on yellow highlighting. imogul Excel 2 09-28-2011 04:11 AM

Other Forums: Access Forums - Senior Forums

All times are GMT -7. The time now is 06:20 AM.


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