E
Elizabeth Swoope
Using Word 2007.
I promise that I have looked through the code here but my programming skills
are rusty and VBA is NOT my "thing".
I have a long (200+ page) document that begins life as an HTML file
generated by a test bank program. I've written a long macro that does a lot
of cleanup work using find/replace and it works great. However, I'm not quite
satisfied with my results. This test bank doesn't get monkeyed with often so
I don't care how slow or clunky the macro is and I don't care to spend hours
and hours getting it perfect.
The edited document contains between 450 and 500 questions, each in the
format shown below. All paragraphs are in the Normal style (with no space
above or below) except the question number (e.g, 13 of 465), which is in
Normal (Web) (which has space before and after). I'll show returns as <r>. =
indicates a horizontal rule that is the full width of the page, - indicates a
horizontal rule that is half the width of the page.
===========================================
13 of 465<r>
This is the question. It may be one or more paragraphs. Each paragraph ends
with two returns.<r>
<r>
(some questions have a graphic)<r>
<r>
a. This is the first answer.<r>
b. This is the second answer.<r>
c. This is the third answer.<r>
d. This is the fourth answer.<r>
-------------------------------------------<r>
This is the feedback shown if the student gives the wrong answer. It may be
more than one paragraph.<r>
<r>
a.<r>
==================================================
14 of 465<r>
etc.
I want the information below the possible answers to show the correct answer
before the feedback, like this:
-------------------------------------------<r>
a.<r>
This is the feedback shown if the student gives the wrong answer. It may be
more than one paragraph.<r>
==================================================
I have recorded a macro which finds the correct answer, cuts it, then
searches for the graphic immediately above it (which is always the short
horizontal rule) and pastes it after that graphic, then formats with a style
that has space below. I'm not worried about two hard returns in a row right
now because I can search and replace those later. I just want to get the
answer and the feedback swapped for now.
Here's the code that I recorded. I just need to know what to put around it
to make it run repeatedly until it gets to the end of the document. I'm sure
this is a stupidly simple thing, but I'm having no luck. I understand the
concept of loops, I just don't know what variable to check for to do this
until the end of the document is reached.
If there's a way to search for a horizontal rule (and differentiate between
full-width and 50% width), I'm all eyes because I may need to differentiate
between graphics that are pictures and those that are lines.
Sub SwapAnswer()
'
' SwapAnswer Macro
'
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^p^$.^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Cut
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^g^p"
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.PasteAndFormat (wdPasteDefault)
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.Style = ActiveDocument.Styles("Body Text")
Selection.TypeBackspace
End Sub
Thanks in advance for any and all help. I'm sure I'm missing something very
simple.
liz
I promise that I have looked through the code here but my programming skills
are rusty and VBA is NOT my "thing".
I have a long (200+ page) document that begins life as an HTML file
generated by a test bank program. I've written a long macro that does a lot
of cleanup work using find/replace and it works great. However, I'm not quite
satisfied with my results. This test bank doesn't get monkeyed with often so
I don't care how slow or clunky the macro is and I don't care to spend hours
and hours getting it perfect.
The edited document contains between 450 and 500 questions, each in the
format shown below. All paragraphs are in the Normal style (with no space
above or below) except the question number (e.g, 13 of 465), which is in
Normal (Web) (which has space before and after). I'll show returns as <r>. =
indicates a horizontal rule that is the full width of the page, - indicates a
horizontal rule that is half the width of the page.
===========================================
13 of 465<r>
This is the question. It may be one or more paragraphs. Each paragraph ends
with two returns.<r>
<r>
(some questions have a graphic)<r>
<r>
a. This is the first answer.<r>
b. This is the second answer.<r>
c. This is the third answer.<r>
d. This is the fourth answer.<r>
-------------------------------------------<r>
This is the feedback shown if the student gives the wrong answer. It may be
more than one paragraph.<r>
<r>
a.<r>
==================================================
14 of 465<r>
etc.
I want the information below the possible answers to show the correct answer
before the feedback, like this:
-------------------------------------------<r>
a.<r>
This is the feedback shown if the student gives the wrong answer. It may be
more than one paragraph.<r>
==================================================
I have recorded a macro which finds the correct answer, cuts it, then
searches for the graphic immediately above it (which is always the short
horizontal rule) and pastes it after that graphic, then formats with a style
that has space below. I'm not worried about two hard returns in a row right
now because I can search and replace those later. I just want to get the
answer and the feedback swapped for now.
Here's the code that I recorded. I just need to know what to put around it
to make it run repeatedly until it gets to the end of the document. I'm sure
this is a stupidly simple thing, but I'm having no luck. I understand the
concept of loops, I just don't know what variable to check for to do this
until the end of the document is reached.
If there's a way to search for a horizontal rule (and differentiate between
full-width and 50% width), I'm all eyes because I may need to differentiate
between graphics that are pictures and those that are lines.
Sub SwapAnswer()
'
' SwapAnswer Macro
'
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^p^$.^p"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.Cut
Selection.Find.ClearFormatting
With Selection.Find
.Text = "^g^p"
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.PasteAndFormat (wdPasteDefault)
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.Style = ActiveDocument.Styles("Body Text")
Selection.TypeBackspace
End Sub
Thanks in advance for any and all help. I'm sure I'm missing something very
simple.
liz