![]() |
|
![]() |
|
Thread Tools | Display Modes |
|
#1
|
||||
|
||||
![]()
If the document is exactly as you describe then the following should work. It does however rely on there being the same exact number of lines for each question and answer.
Code:
Sub MarkAnswers() Dim oRng As Range, oAns As Range Dim iQuest As Integer, iAns As Integer Const sNumList As String = "0123456789" On Error GoTo lbl_Exit For iQuest = 1 To ActiveDocument.Paragraphs.Count Step 7 'step through the questions Set oRng = ActiveDocument.Paragraphs(iQuest).Range 'get the first paragraph of the question oRng.MoveEnd wdParagraph, 6 'Get the last empty paragraph of the block Set oAns = oRng.Paragraphs(6).Range 'set a range to the answer line oAns.Collapse 1 'collapse the range to its start oAns.MoveEndWhile sNumList 'move the end of the range to the end of the answer number If Len(oAns.Text) > 0 Then 'if there is a number on that line iAns = oAns.Text + 1 'add a 1 to that number - to correspond to the answer number oRng.Paragraphs(iAns).Range.Font.ColorIndex = wdRed ' colour that paragraph red End If Next iQuest 'and process the next question lbl_Exit: 'clear up Set oRng = Nothing Set oAns = Nothing Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#2
|
|||
|
|||
![]()
Thank you Graham! It colors the right options nicely. Yet after the coloring, it does not delete the lines that provide the answers (in the example, the line of "2 (option 2. is the correct answer to the 1st question)" need to be deleted). I tried to do so by adding "oAns.Delete" after "End If" but then it only deletes the number, not the whole line/paragraph.
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Change Color (Being provided between the two codes) | bnyamin | Word VBA | 4 | 05-16-2017 10:55 PM |
Macro- find and replace from preselected options based on frequency (like an Ad libs) | blondie | Word VBA | 0 | 02-27-2017 01:41 PM |
![]() |
jrfoley3 | Excel | 3 | 08-26-2016 10:49 PM |
![]() |
jaradani | Word | 4 | 10-12-2014 09:42 PM |
Changing bar color automatically | Mahmuz | PowerPoint | 0 | 03-28-2012 11:49 PM |