![]() |
|
![]() |
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
![]()
Hello friends,
So, it's exam time and my small school has a limited number of scantron machines, few of which are broken. It seems that I have to hand grade some tests in order to meet the deadline. How would I go about creating a macro that will delete the unneeded answers to a multiple choice question? The questions are in plain text, with "A", "B", "C", "D", & "E". The "right" answer starts with a BOLDed and UNDERLINEd letter. Example: 94. Test Question A. answer A B. answer B C. answer C D. answer D E. answer E |
#2
|
||||
|
||||
![]()
Try:
Code:
Sub Demo() Application.ScreenUpdating = False With ActiveDocument.Range With .Find .ClearFormatting .Replacement.ClearFormatting .Text = "[A-Z]." .Replacement.Text = "" .Font.Bold = False .Font.Underline = wdUnderlineNone .Forward = True .Wrap = wdFindStop .Format = True .MatchWildcards = True .Execute End With Do While .Find.Found With .Duplicate If .Start = .Paragraphs.First.Range.Start Then .Paragraphs.First.Range.Text = vbNullString End If End With .Collapse wdCollapseEnd .Find.Execute Loop End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
![]()
Hi! Thank you for such the quick response.
Your macro worked to a degree. It deleted all the unneccessary "answer letters" but still left the "answer choices". This is what I'm getting now: 94. Test Question answer A B. answer B answer C answer D answer E with "B." being the right answer |
#4
|
||||
|
||||
![]()
The sample data in your first post implied the answer 'choice' and its text were in the same paragraph - and that's what I coded for. With data such as you described, all that would be left is:
94. Test Question B. answer B The only reason the answer text would remain is if it were not part of the same paragraph. I'd rather not waste more time guessing what your document's layout is, so perhaps you could attach a document to a post with some truly representative data (delete anything sensitive)? You do this via the paperclip symbol on the 'Go Advanced' tab at the bottom of this screen.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
![]()
I have added a sample with the formatting from the document intact. I now realize that the text is embedded in a table. I appreciate your help in helping me with this issue!
![]() |
#6
|
||||
|
||||
![]()
In that case, you could change:
.Paragraphs.First.Range.Text = vbNullString to: .Rows(1).Delete
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
![]()
WOW thank you so much, you're awesome! That was exactly what I needed. You saved me so much work and time! ^_^
|
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
rsrasc | Word VBA | 7 | 03-28-2014 12:28 PM |
![]() |
ENEMALI | Word VBA | 1 | 09-29-2013 09:05 PM |
![]() |
Microsoftenquirer1000 | Word | 2 | 08-12-2012 02:49 PM |
Linking multiple choice questions to answers | Microsoftenquirer1000 | Word | 1 | 06-11-2012 06:53 AM |
![]() |
excelledsoftware | PowerPoint | 2 | 03-01-2012 07:29 PM |