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

Re: Another dreaded "loop through the document" question by Doug

Doug
Thu Jan 10 20:04:14 PST 2008

There is little doubt that what you want to do is possible, but you
facsimile example does not provide sufficient information.

Copy and paste several question/answer segments into a message that you post
back here so that we can get a better idea of what you are starting with.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Elizabeth Swoope" <ElizabethSwoope@discussions.microsoft.com> wrote in
message news:F45AF4D4-4FB6-4043-8707-8587985EC39A@microsoft.com...
> 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



Re: Another dreaded "loop through the document" question by ElizabethSwoope

ElizabethSwoope
Fri Jan 11 03:25:01 PST 2008

Doug,

Okay, I've posted several questions. The code I posted works ONCE each time
the macro runs. It finds the right answer, moves it above the explanation,
and changes the style to one that has space below rather than using Enter
Enter.

I just need to know how to make the code repeat until it gets to the end of
the document. I need a loop, I just don't know what the magic "end of file"
condition is. I could fake it by looping 465 times but there aren't always
465 questions and I don't really want to have to remember to change the magic
number each time.

Thanks,

liz

-------

1 of 465
The fastest, most powerful computers often must be fed data by several fast,
powerful, multi-user and multitasking computers. In which category are the
computers that feed the data?

a. super computer
b. mainframe
c. minicomputer
d. microcomputer
________________________________________
Mainframes are used to feed data to the fastest, most powerful computers
(supercomputers).

b.
________________________________________
2 of 465
The smallest, least powerful, least expensive computers are in which category?

a. super computer
b. mainframe
c. minicomputer
d. microcomputer
________________________________________
Microcomputers are the smallest, least powerful, least expensive computers.

d.
________________________________________
3 of 465
Computers that are usually multi-user and multitasking, but which can
sometimes be devoted to performing a single task, are in which category?

a. super computer
b. mainframe
c. minicomputer
d. microcomputer
________________________________________
Minicomputers are usually multi-user and multitasking, but can sometimes be
devoted to performing a single task.

c.
________________________________________
4 of 465
Which category of computers is the largest, fastest, and most powerful and
is both multi-user and multitasking?

a. super computer
b. mainframe
c. minicomputer
d. microcomputer
________________________________________
Super computers are the largest, fastest, and most powerful computers and
are both multi-user and multitasking.

a.
________________________________________


"Doug Robbins - Word MVP" wrote:

> There is little doubt that what you want to do is possible, but you
> facsimile example does not provide sufficient information.
>
> Copy and paste several question/answer segments into a message that you post
> back here so that we can get a better idea of what you are starting with.


"Doug Robbins - Word MVP" wrote:



Re: Another dreaded "loop through the document" question by Doug

Doug
Fri Jan 11 12:37:42 PST 2008

You do not need to use a macro for this.

In the Replace dialog, click on the "More" button and then check the "Use
wildcards" box and in the "Find what:" control, enter

([A-z.,\- \(\)]{1,}^13)(^13)([a-d]{1})(.^13)

and in the "Replace with:" control, enter

\3\4\1

Then click on "Replace All"

For an explanation, See the article "Finding and replacing characters using
wildcards" at:

http://www.word.mvps.org/FAQs/General/UsingWildcards.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Elizabeth Swoope" <ElizabethSwoope@discussions.microsoft.com> wrote in
message news:CB3D2290-40CB-464D-AF06-23D7C1DA59EC@microsoft.com...
> Doug,
>
> Okay, I've posted several questions. The code I posted works ONCE each
> time
> the macro runs. It finds the right answer, moves it above the explanation,
> and changes the style to one that has space below rather than using Enter
> Enter.
>
> I just need to know how to make the code repeat until it gets to the end
> of
> the document. I need a loop, I just don't know what the magic "end of
> file"
> condition is. I could fake it by looping 465 times but there aren't always
> 465 questions and I don't really want to have to remember to change the
> magic
> number each time.
>
> Thanks,
>
> liz
>
> -------
>
> 1 of 465
> The fastest, most powerful computers often must be fed data by several
> fast,
> powerful, multi-user and multitasking computers. In which category are the
> computers that feed the data?
>
> a. super computer
> b. mainframe
> c. minicomputer
> d. microcomputer
> ________________________________________
> Mainframes are used to feed data to the fastest, most powerful computers
> (supercomputers).
>
> b.
> ________________________________________
> 2 of 465
> The smallest, least powerful, least expensive computers are in which
> category?
>
> a. super computer
> b. mainframe
> c. minicomputer
> d. microcomputer
> ________________________________________
> Microcomputers are the smallest, least powerful, least expensive
> computers.
>
> d.
> ________________________________________
> 3 of 465
> Computers that are usually multi-user and multitasking, but which can
> sometimes be devoted to performing a single task, are in which category?
>
> a. super computer
> b. mainframe
> c. minicomputer
> d. microcomputer
> ________________________________________
> Minicomputers are usually multi-user and multitasking, but can sometimes
> be
> devoted to performing a single task.
>
> c.
> ________________________________________
> 4 of 465
> Which category of computers is the largest, fastest, and most powerful and
> is both multi-user and multitasking?
>
> a. super computer
> b. mainframe
> c. minicomputer
> d. microcomputer
> ________________________________________
> Super computers are the largest, fastest, and most powerful computers and
> are both multi-user and multitasking.
>
> a.
> ________________________________________
>
>
> "Doug Robbins - Word MVP" wrote:
>
>> There is little doubt that what you want to do is possible, but you
>> facsimile example does not provide sufficient information.
>>
>> Copy and paste several question/answer segments into a message that you
>> post
>> back here so that we can get a better idea of what you are starting with.
>
>
> "Doug Robbins - Word MVP" wrote:
>
>



Re: Another dreaded "loop through the document" question by ElizabethSwoope

ElizabethSwoope
Fri Jan 11 13:44:00 PST 2008

Doug,

Alas, that did not work. I got 0 replacements. When I have time to look at
your answer, I will figure out what those long strings mean and I may be able
to figure out where the problem is. I'll be tickled if a find/replace will do
the trick!

I will get back to you later with the results after I've had time to tinker.
Thanks for pointing me in the direction that will probably result in a
solution!

liz

"Doug Robbins - Word MVP" wrote:

> You do not need to use a macro for this.
>
> In the Replace dialog, click on the "More" button and then check the "Use
> wildcards" box and in the "Find what:" control, enter
>
> ([A-z.,\- \(\)]{1,}^13)(^13)([a-d]{1})(.^13)
>
> and in the "Replace with:" control, enter
>
> \3\4\1
>
> Then click on "Replace All"
>
> For an explanation, See the article "Finding and replacing characters using
> wildcards" at:
>
> http://www.word.mvps.org/FAQs/General/UsingWildcards.htm
>
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> "Elizabeth Swoope" <ElizabethSwoope@discussions.microsoft.com> wrote in
> message news:CB3D2290-40CB-464D-AF06-23D7C1DA59EC@microsoft.com...
> > Doug,
> >
> > Okay, I've posted several questions. The code I posted works ONCE each
> > time
> > the macro runs. It finds the right answer, moves it above the explanation,
> > and changes the style to one that has space below rather than using Enter
> > Enter.
> >
> > I just need to know how to make the code repeat until it gets to the end
> > of
> > the document. I need a loop, I just don't know what the magic "end of
> > file"
> > condition is. I could fake it by looping 465 times but there aren't always
> > 465 questions and I don't really want to have to remember to change the
> > magic
> > number each time.
> >
> > Thanks,
> >
> > liz
> >
> > -------
> >
> > 1 of 465
> > The fastest, most powerful computers often must be fed data by several
> > fast,
> > powerful, multi-user and multitasking computers. In which category are the
> > computers that feed the data?
> >
> > a. super computer
> > b. mainframe
> > c. minicomputer
> > d. microcomputer
> > ________________________________________
> > Mainframes are used to feed data to the fastest, most powerful computers
> > (supercomputers).
> >
> > b.
> > ________________________________________
> > 2 of 465
> > The smallest, least powerful, least expensive computers are in which
> > category?
> >
> > a. super computer
> > b. mainframe
> > c. minicomputer
> > d. microcomputer
> > ________________________________________
> > Microcomputers are the smallest, least powerful, least expensive
> > computers.
> >
> > d.
> > ________________________________________
> > 3 of 465
> > Computers that are usually multi-user and multitasking, but which can
> > sometimes be devoted to performing a single task, are in which category?
> >
> > a. super computer
> > b. mainframe
> > c. minicomputer
> > d. microcomputer
> > ________________________________________
> > Minicomputers are usually multi-user and multitasking, but can sometimes
> > be
> > devoted to performing a single task.
> >
> > c.
> > ________________________________________
> > 4 of 465
> > Which category of computers is the largest, fastest, and most powerful and
> > is both multi-user and multitasking?
> >
> > a. super computer
> > b. mainframe
> > c. minicomputer
> > d. microcomputer
> > ________________________________________
> > Super computers are the largest, fastest, and most powerful computers and
> > are both multi-user and multitasking.
> >
> > a.
> > ________________________________________
> >
> >
> > "Doug Robbins - Word MVP" wrote:
> >
> >> There is little doubt that what you want to do is possible, but you
> >> facsimile example does not provide sufficient information.
> >>
> >> Copy and paste several question/answer segments into a message that you
> >> post
> >> back here so that we can get a better idea of what you are starting with.
> >
> >
> > "Doug Robbins - Word MVP" wrote:
> >
> >
>
>
>

Re: Another dreaded "loop through the document" question by Doug

Doug
Fri Jan 11 14:01:36 PST 2008

I copied and pasted the text from your message into a Word document, then
used Find and Replace to replace the line breaks ^l with ^p, then removed
the superfluous carriage returns at the ends of the individual lines to
restore the proper paragraph arrangement.

Then, using a Wild Card replace with the strings that I gave you, the
resulted in 4 replacements with the following being produced:

1 of 465

The fastest, most powerful computers often must be fed data by several fast,
powerful, multi-user and multitasking computers. In which category are the
computers that feed the data?



a. super computer

b. mainframe

c. minicomputer

d. microcomputer

________________________________________

b.

Mainframes are used to feed data to the fastest, most powerful computers
(supercomputers).

________________________________________

2 of 465

The smallest, least powerful, least expensive computers are in which
category?



a. super computer

b. mainframe

c. minicomputer

d. microcomputer

________________________________________

d.

Microcomputers are the smallest, least powerful, least expensive computers.

________________________________________

3 of 465

Computers that are usually multi-user and multitasking, but which can

sometimes be devoted to performing a single task, are in which category?



a. super computer

b. mainframe

c. minicomputer

d. microcomputer

________________________________________

c.

Minicomputers are usually multi-user and multitasking, but can sometimes be
devoted to performing a single task.

________________________________________

4 of 465

Which category of computers is the largest, fastest, and most powerful and
is both multi-user and multitasking?



a. super computer

b. mainframe

c. minicomputer

d. microcomputer

________________________________________

a.

Super computers are the largest, fastest, and most powerful computers and
are both multi-user and multitasking.

________________________________________


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Elizabeth Swoope" <ElizabethSwoope@discussions.microsoft.com> wrote in
message news:4D8FEBC4-5C16-44AA-AA1B-B4B7A0B372AD@microsoft.com...
> Doug,
>
> Alas, that did not work. I got 0 replacements. When I have time to look at
> your answer, I will figure out what those long strings mean and I may be
> able
> to figure out where the problem is. I'll be tickled if a find/replace will
> do
> the trick!
>
> I will get back to you later with the results after I've had time to
> tinker.
> Thanks for pointing me in the direction that will probably result in a
> solution!
>
> liz
>
> "Doug Robbins - Word MVP" wrote:
>
>> You do not need to use a macro for this.
>>
>> In the Replace dialog, click on the "More" button and then check the "Use
>> wildcards" box and in the "Find what:" control, enter
>>
>> ([A-z.,\- \(\)]{1,}^13)(^13)([a-d]{1})(.^13)
>>
>> and in the "Replace with:" control, enter
>>
>> \3\4\1
>>
>> Then click on "Replace All"
>>
>> For an explanation, See the article "Finding and replacing characters
>> using
>> wildcards" at:
>>
>> http://www.word.mvps.org/FAQs/General/UsingWildcards.htm
>>
>>
>> --
>> Hope this helps.
>>
>> Please reply to the newsgroup unless you wish to avail yourself of my
>> services on a paid consulting basis.
>>
>> Doug Robbins - Word MVP
>>
>> "Elizabeth Swoope" <ElizabethSwoope@discussions.microsoft.com> wrote in
>> message news:CB3D2290-40CB-464D-AF06-23D7C1DA59EC@microsoft.com...
>> > Doug,
>> >
>> > Okay, I've posted several questions. The code I posted works ONCE each
>> > time
>> > the macro runs. It finds the right answer, moves it above the
>> > explanation,
>> > and changes the style to one that has space below rather than using
>> > Enter
>> > Enter.
>> >
>> > I just need to know how to make the code repeat until it gets to the
>> > end
>> > of
>> > the document. I need a loop, I just don't know what the magic "end of
>> > file"
>> > condition is. I could fake it by looping 465 times but there aren't
>> > always
>> > 465 questions and I don't really want to have to remember to change the
>> > magic
>> > number each time.
>> >
>> > Thanks,
>> >
>> > liz
>> >
>> > -------
>> >
>> > 1 of 465
>> > The fastest, most powerful computers often must be fed data by several
>> > fast,
>> > powerful, multi-user and multitasking computers. In which category are
>> > the
>> > computers that feed the data?
>> >
>> > a. super computer
>> > b. mainframe
>> > c. minicomputer
>> > d. microcomputer
>> > ________________________________________
>> > Mainframes are used to feed data to the fastest, most powerful
>> > computers
>> > (supercomputers).
>> >
>> > b.
>> > ________________________________________
>> > 2 of 465
>> > The smallest, least powerful, least expensive computers are in which
>> > category?
>> >
>> > a. super computer
>> > b. mainframe
>> > c. minicomputer
>> > d. microcomputer
>> > ________________________________________
>> > Microcomputers are the smallest, least powerful, least expensive
>> > computers.
>> >
>> > d.
>> > ________________________________________
>> > 3 of 465
>> > Computers that are usually multi-user and multitasking, but which can
>> > sometimes be devoted to performing a single task, are in which
>> > category?
>> >
>> > a. super computer
>> > b. mainframe
>> > c. minicomputer
>> > d. microcomputer
>> > ________________________________________
>> > Minicomputers are usually multi-user and multitasking, but can
>> > sometimes
>> > be
>> > devoted to performing a single task.
>> >
>> > c.
>> > ________________________________________
>> > 4 of 465
>> > Which category of computers is the largest, fastest, and most powerful
>> > and
>> > is both multi-user and multitasking?
>> >
>> > a. super computer
>> > b. mainframe
>> > c. minicomputer
>> > d. microcomputer
>> > ________________________________________
>> > Super computers are the largest, fastest, and most powerful computers
>> > and
>> > are both multi-user and multitasking.
>> >
>> > a.
>> > ________________________________________
>> >
>> >
>> > "Doug Robbins - Word MVP" wrote:
>> >
>> >> There is little doubt that what you want to do is possible, but you
>> >> facsimile example does not provide sufficient information.
>> >>
>> >> Copy and paste several question/answer segments into a message that
>> >> you
>> >> post
>> >> back here so that we can get a better idea of what you are starting
>> >> with.
>> >
>> >
>> > "Doug Robbins - Word MVP" wrote:
>> >
>> >
>>
>>
>>



Re: Another dreaded "loop through the document" question by ElizabethSwoope

ElizabethSwoope
Fri Jan 11 16:14:00 PST 2008

Doug,

I was in a hurry when I started tinkering with this (school starts Monday
and my computer lab wasn't ready and the computer guys weren't around so I
was in panic mode), but when I slowed down a bit and went back through it, it
worked! I'd not checked Use wildcards, which explains why it didn't work.\

That is really slick!

However, there's at least one instance in which it isn't working properly.
Haven't had time to try to figure out exactly why.

When the text to be flipped is:

EXST2000 is a folder.

b.

The search highlights only " is a folder. <p><p>b.<p>" and not "EXST2000"
so the swap doesn't work properly. The result is "EXST2000b.<p> is a
folder.<p>"

I don't think it's because "EXST2000" is bold because the entry before it
(which flips properly) is "Masterfiles is a folder." and "Masterfiles" is
bold.

I'll have to spend some time playing with this, but this is a good start. I
may want to clean up the correct answer (remove the extra return and format
as Body Text) before doing the swap, which will require a little bit of
tweaking to the string you gave me.

Anyway, thanks for taking the time to help!

liz

Re: Another dreaded "loop through the document" question by ElizabethSwoope

ElizabethSwoope
Sat Jan 12 05:44:00 PST 2008

Doug,

I have made some progress. I changed your recommended search string to the
following because the feedback includes all sorts of special characters that
were resulting in the only part of the feedback being selected. Rather than
adding more exceptions, I just changed the range:

([ -~)]{1,}^13)(^13)([a-d]{1})(.^13)

However, even though [ and ] characters are included in that range, when the
feedback includes [ (as in "[Shift]"), the feedback is split at the first one
of those characters. I tried adding \[\] to the string and even (\[)(\]) but
that just gave me error messages. I'm sure I'm doing something obvious, but
this is new enough to me that I didn't catch it. I'm going to get away from
it for awhile and maybe fresh perspective will help.

Second problem: Some feedback paragraphs appear perfectly normal (no unusual
characters or formatting) but get split. For example, I get

You should never type spaces at the beginning of a parac.

graph or line ....

instead of

c.

You should never type spaces at the beginning of a paragraph or line....

(ellipsis not in original text)

Third problem:

Some of the feedback is more than one paragraph (two or three, there may be
some that are more than that but I'm not sure). The "flip" only flips the
correct answer and the last feedback paragraph.

The pattern is this:

d. last answer
---------(horizontal line 50% width)
feedback (one or more paragraphs, separated by two hard returns)

feedback (example second paragraph)

a.
=========================(horizontal line, full width)

I have also been able to change the style of the correct answer to Body Text
so that it has space between it and the feedback, so that's more progress.

Re: Another dreaded "loop through the document" question by Doug

Doug
Sat Jan 12 12:39:16 PST 2008

Make sure that when you perform the Replace, the selection is at the
beginning of the document.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Elizabeth Swoope" <ElizabethSwoope@discussions.microsoft.com> wrote in
message news:FC41F702-1F7C-4FA7-9E4A-D2DA62986684@microsoft.com...
> Doug,
>
> I have made some progress. I changed your recommended search string to the
> following because the feedback includes all sorts of special characters
> that
> were resulting in the only part of the feedback being selected. Rather
> than
> adding more exceptions, I just changed the range:
>
> ([ -~)]{1,}^13)(^13)([a-d]{1})(.^13)
>
> However, even though [ and ] characters are included in that range, when
> the
> feedback includes [ (as in "[Shift]"), the feedback is split at the first
> one
> of those characters. I tried adding \[\] to the string and even (\[)(\])
> but
> that just gave me error messages. I'm sure I'm doing something obvious,
> but
> this is new enough to me that I didn't catch it. I'm going to get away
> from
> it for awhile and maybe fresh perspective will help.
>
> Second problem: Some feedback paragraphs appear perfectly normal (no
> unusual
> characters or formatting) but get split. For example, I get
>
> You should never type spaces at the beginning of a parac.
>
> graph or line ....
>
> instead of
>
> c.
>
> You should never type spaces at the beginning of a paragraph or line....
>
> (ellipsis not in original text)
>
> Third problem:
>
> Some of the feedback is more than one paragraph (two or three, there may
> be
> some that are more than that but I'm not sure). The "flip" only flips the
> correct answer and the last feedback paragraph.
>
> The pattern is this:
>
> d. last answer
> ---------(horizontal line 50% width)
> feedback (one or more paragraphs, separated by two hard returns)
>
> feedback (example second paragraph)
>
> a.
> =========================(horizontal line, full width)
>
> I have also been able to change the style of the correct answer to Body
> Text
> so that it has space between it and the feedback, so that's more progress.



Re: Another dreaded "loop through the document" question by ElizabethSwoope

ElizabethSwoope
Sat Jan 12 15:31:02 PST 2008

Doug,

I always start with the cursor at the beginning of the document. I open the
document then start the replaces. The problems that I mentioned in my latest
message occur when the cursor is at the beginning of the document and nothing
is selected. The cursor location isn't the source of my problems.

liz

"Doug Robbins - Word MVP" wrote:

> Make sure that when you perform the Replace, the selection is at the
> beginning of the document.
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP

Re: Another dreaded "loop through the document" question by Doug

Doug
Sun Jan 13 19:56:03 PST 2008

Looks like a macro method might be required.

The following will re-arrange the answers to all of the questions except for
the last one in the document.

Dim myrange As Range
Dim i As Long, j As Long
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
With Selection.Find
Do While .Execute(findText:="[0-9]{1,} of [0-9]{1,}",
Forward:=True, _
MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) = True
Set myrange = Selection.Range
With ActiveDocument
If Not .Paragraphs(1).Range.start = myrange.start Then
For i = 1 To .Paragraphs.Count
If .Paragraphs(i).Range.start = myrange.start Then
Set myrange = .Paragraphs(i - 2).Range
Exit For
End If
Next i
j = 3
Do While Left(.Paragraphs(i - j).Range, 1) <> "d"
j = j + 1
Loop
.Paragraphs(i - j + 2).Range.InsertBefore myrange.Text '
& vbCr
myrange.Delete
End If
End With
Selection.Collapse wdCollapseEnd
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Elizabeth Swoope" <ElizabethSwoope@discussions.microsoft.com> wrote in
message news:D33B0A36-5835-414B-863F-3EA396126B3C@microsoft.com...
> Doug,
>
> I always start with the cursor at the beginning of the document. I open
> the
> document then start the replaces. The problems that I mentioned in my
> latest
> message occur when the cursor is at the beginning of the document and
> nothing
> is selected. The cursor location isn't the source of my problems.
>
> liz
>
> "Doug Robbins - Word MVP" wrote:
>
>> Make sure that when you perform the Replace, the selection is at the
>> beginning of the document.
>>
>> --
>> Hope this helps.
>>
>> Please reply to the newsgroup unless you wish to avail yourself of my
>> services on a paid consulting basis.
>>
>> Doug Robbins - Word MVP



Re: Another dreaded "loop through the document" question by ElizabethSwoope

ElizabethSwoope
Sun Jan 13 20:19:01 PST 2008

Doug,

Just wanted to acknowledge your response. Tomorrow is my first day of class
for the semester and it's five hours of talking to the students so I may not
have a chance to try the macro until Tuesday. I'll let you know how it works
and I promise I'll try to translate what the macro is doing into English so I
can understand it.

Thanks,

liz

"Doug Robbins - Word MVP" wrote:

> Looks like a macro method might be required.
>
> The following will re-arrange the answers to all of the questions except for
> the last one in the document.
>
> Dim myrange As Range
> Dim i As Long, j As Long
> Selection.HomeKey wdStory
> Selection.Find.ClearFormatting
> With Selection.Find
> Do While .Execute(findText:="[0-9]{1,} of [0-9]{1,}",
> Forward:=True, _
> MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) = True
> Set myrange = Selection.Range
> With ActiveDocument
> If Not .Paragraphs(1).Range.start = myrange.start Then
> For i = 1 To .Paragraphs.Count
> If .Paragraphs(i).Range.start = myrange.start Then
> Set myrange = .Paragraphs(i - 2).Range
> Exit For
> End If
> Next i
> j = 3
> Do While Left(.Paragraphs(i - j).Range, 1) <> "d"
> j = j + 1
> Loop
> .Paragraphs(i - j + 2).Range.InsertBefore myrange.Text '
> & vbCr
> myrange.Delete
> End If
> End With
> Selection.Collapse wdCollapseEnd
> Loop
> End With
>
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP


Re: Another dreaded "loop through the document" question by ElizabethSwoope

ElizabethSwoope
Mon Jan 14 03:09:06 PST 2008

Doug,

I'm up early this morning and decided I'd try the macro.

The following lines are in red, which I assume means there's some sort of
error. Unfortunately, I'm not familiar with VB so can't diagnose the problem,
although I'll dig out some books and see if I can figure it out.

Do While .Execute(findText:="[0-9]{1,} of [0-9]{1,}",
Forward:=True, _
MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) = True

and

& vbCr

Thanks,

liz

"Doug Robbins - Word MVP" wrote:

> Looks like a macro method might be required.
>
> The following will re-arrange the answers to all of the questions except for
> the last one in the document.
>
> Dim myrange As Range
> Dim i As Long, j As Long
> Selection.HomeKey wdStory
> Selection.Find.ClearFormatting
> With Selection.Find
> Do While .Execute(findText:="[0-9]{1,} of [0-9]{1,}",
> Forward:=True, _
> MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) = True
> Set myrange = Selection.Range
> With ActiveDocument
> If Not .Paragraphs(1).Range.start = myrange.start Then
> For i = 1 To .Paragraphs.Count
> If .Paragraphs(i).Range.start = myrange.start Then
> Set myrange = .Paragraphs(i - 2).Range
> Exit For
> End If
> Next i
> j = 3
> Do While Left(.Paragraphs(i - j).Range, 1) <> "d"
> j = j + 1
> Loop
> .Paragraphs(i - j + 2).Range.InsertBefore myrange.Text '
> & vbCr
> myrange.Delete
> End If
> End With
> Selection.Collapse wdCollapseEnd
> Loop
> End With
>
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> "Elizabeth Swoope" <ElizabethSwoope@discussions.microsoft.com> wrote in
> message news:D33B0A36-5835-414B-863F-3EA396126B3C@microsoft.com...
> > Doug,
> >
> > I always start with the cursor at the beginning of the document. I open
> > the
> > document then start the replaces. The problems that I mentioned in my
> > latest
> > message occur when the cursor is at the beginning of the document and
> > nothing
> > is selected. The cursor location isn't the source of my problems.
> >
> > liz
> >
> > "Doug Robbins - Word MVP" wrote:
> >
> >> Make sure that when you perform the Replace, the selection is at the
> >> beginning of the document.
> >>
> >> --
> >> Hope this helps.
> >>
> >> Please reply to the newsgroup unless you wish to avail yourself of my
> >> services on a paid consulting basis.
> >>
> >> Doug Robbins - Word MVP
>
>
>

Re: Another dreaded "loop through the document" question by ElizabethSwoope

ElizabethSwoope
Mon Jan 14 03:20:01 PST 2008

Doug,

I realized that the red text might indicate lines that were wrapped that
shouldn't be and that fixed the red problem.

However, the following line produces the error "Run-time error '5941': The
requested member of the collection does not exist."

Do While Left(.Paragraphs(i - j).Range, 1) <> "d"

I will try to do some reasearch and see if I can at least understand the
keywords and what the macro is trying to do.

Thanks,

liz

"Doug Robbins - Word MVP" wrote:

> Looks like a macro method might be required.
>
> The following will re-arrange the answers to all of the questions except for
> the last one in the document.
>
> Dim myrange As Range
> Dim i As Long, j As Long
> Selection.HomeKey wdStory
> Selection.Find.ClearFormatting
> With Selection.Find
> Do While .Execute(findText:="[0-9]{1,} of [0-9]{1,}",
> Forward:=True, _
> MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) = True
> Set myrange = Selection.Range
> With ActiveDocument
> If Not .Paragraphs(1).Range.start = myrange.start Then
> For i = 1 To .Paragraphs.Count
> If .Paragraphs(i).Range.start = myrange.start Then
> Set myrange = .Paragraphs(i - 2).Range
> Exit For
> End If
> Next i
> j = 3
> Do While Left(.Paragraphs(i - j).Range, 1) <> "d"
> j = j + 1
> Loop
> .Paragraphs(i - j + 2).Range.InsertBefore myrange.Text '
> & vbCr
> myrange.Delete
> End If
> End With
> Selection.Collapse wdCollapseEnd
> Loop
> End With
>
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> "Elizabeth Swoope" <ElizabethSwoope@discussions.microsoft.com> wrote in
> message news:D33B0A36-5835-414B-863F-3EA396126B3C@microsoft.com...
> > Doug,
> >
> > I always start with the cursor at the beginning of the document. I open
> > the
> > document then start the replaces. The problems that I mentioned in my
> > latest
> > message occur when the cursor is at the beginning of the document and
> > nothing
> > is selected. The cursor location isn't the source of my problems.
> >
> > liz
> >
> > "Doug Robbins - Word MVP" wrote:
> >
> >> Make sure that when you perform the Replace, the selection is at the
> >> beginning of the document.
> >>
> >> --
> >> Hope this helps.
> >>
> >> Please reply to the newsgroup unless you wish to avail yourself of my
> >> services on a paid consulting basis.
> >>
> >> Doug Robbins - Word MVP
>
>
>

Re: Another dreaded "loop through the document" question by Doug

Doug
Mon Jan 14 03:44:46 PST 2008

That problem is probably caused by the first paragraph in the document not
being the one that contains 1 of 465

If you were to temporarily cut any paragraphs before that one and copy them
to a new document, then run the macro on the document containing the
questions, it should work OK. After running it, then you could copy the
information back into the document.

What is happening is that the macro is finding the # of ### string and then
stepping back through the paragraphs in the document, skipping the previous
couple until it comes to the d. of the fourth choice item. It then copies
the a. b. c. or d. of the correct answer into the position ahead of the
explanation, before deleting that a. b. c. or d. from its original location.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Elizabeth Swoope" <ElizabethSwoope@discussions.microsoft.com> wrote in
message news:DC7B582F-F207-437C-80A4-410029A716FD@microsoft.com...
> Doug,
>
> I realized that the red text might indicate lines that were wrapped that
> shouldn't be and that fixed the red problem.
>
> However, the following line produces the error "Run-time error '5941': The
> requested member of the collection does not exist."
>
> Do While Left(.Paragraphs(i - j).Range, 1) <> "d"
>
> I will try to do some reasearch and see if I can at least understand the
> keywords and what the macro is trying to do.
>
> Thanks,
>
> liz
>
> "Doug Robbins - Word MVP" wrote:
>
>> Looks like a macro method might be required.
>>
>> The following will re-arrange the answers to all of the questions except
>> for
>> the last one in the document.
>>
>> Dim myrange As Range
>> Dim i As Long, j As Long
>> Selection.HomeKey wdStory
>> Selection.Find.ClearFormatting
>> With Selection.Find
>> Do While .Execute(findText:="[0-9]{1,} of [0-9]{1,}",
>> Forward:=True, _
>> MatchWildcards:=True, MatchCase:=True, Wrap:=wdFindStop) =
>> True
>> Set myrange = Selection.Range
>> With ActiveDocument
>> If Not .Paragraphs(1).Range.start = myrange.start Then
>> For i = 1 To .Paragraphs.Count
>> If .Paragraphs(i).Range.start = myrange.start
>> Then
>> Set myrange = .Paragraphs(i - 2).Range
>> Exit For
>> End If
>> Next i
>> j = 3
>> Do While Left(.Paragraphs(i - j).Range, 1) <> "d"
>> j = j + 1
>> Loop
>> .Paragraphs(i - j + 2).Range.InsertBefore
>> myrange.Text '
>> & vbCr
>> myrange.Delete
>> End If
>> End With
>> Selection.Collapse wdCollapseEnd
>> Loop
>> End With
>>
>>
>> --
>> Hope this helps.
>>
>> Please reply to the newsgroup unless you wish to avail yourself of my
>> services on a paid consulting basis.
>>
>> Doug Robbins - Word MVP
>>
>> "Elizabeth Swoope" <ElizabethSwoope@discussions.microsoft.com> wrote in
>> message news:D33B0A36-5835-414B-863F-3EA396126B3C@microsoft.com...
>> > Doug,
>> >
>> > I always start with the cursor at the beginning of the document. I open
>> > the
>> > document then start the replaces. The problems that I mentioned in my
>> > latest
>> > message occur when the cursor is at the beginning of the document and
>> > nothing
>> > is selected. The cursor location isn't the source of my problems.
>> >
>> > liz
>> >
>> > "Doug Robbins - Word MVP" wrote:
>> >
>> >> Make sure that when you perform the Replace, the selection is at the
>> >> beginning of the document.
>> >>
>> >> --
>> >> Hope this helps.
>> >>
>> >> Please reply to the newsgroup unless you wish to avail yourself of my
>> >> services on a paid consulting basis.
>> >>
>> >> Doug Robbins - Word MVP
>>
>>
>>



Re: Another dreaded "loop through the document" question by ElizabethSwoope

ElizabethSwoope
Mon Jan 14 07:10:01 PST 2008

Doug,

Cutting the text at the top of the document resolved the problem and I don't
mind editing the last question myself.

However (and please don't take this as criticism because it's not; I'm just
reporting what's happening and I may be expecting too much)... the macro
bebops along fairly quickly for the first few questions. Then it slows to a
crawl. I finally had to shut the computer down after an hour and it was about
1/3 of the way through. At this rate, it's going to take 3-4 hours (maybe
more since it seems slower on each subsequent questions) to process the
entire file, which is 212 pages long. I'm just reporting the behavior on the
off chance there's some little tweak that can be made.

I had to turn off Word's autosave and the computer's screen saver to keep
things from locking up.

Anyway, it appears that the macro functions exactly as it needs to and I
think I can make the other formatting changes (mainly style assignments and
changes to try to "glue" the entire question together and get the spacing the
way I want it) myself.

I'm going to take some time to study the macro within the next day or two. I
understand in theory what it's doing but need to absorb the details.

Thanks again for all your help. You've definitely earned your MVP title!

liz

Re: Another dreaded "loop through the document" question by Doug

Doug
Mon Jan 14 12:11:57 PST 2008

The reason that it slows down is because each time it finds a question
number, this block of code is going back to the start of the document and
working through each paragraph if turn to see if it is the one containing
the found question number so that it knows what paragraph number (i) it is
in the document. I'll have a look at changing the code so that perhaps it
only has to go back to the last question for which it found (i) and then
count forward from that spot.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Elizabeth Swoope" <ElizabethSwoope@discussions.microsoft.com> wrote in
message news:8CD9723A-B22F-47BB-AB64-C7FC03AB947A@microsoft.com...
> Doug,
>
> Cutting the text at the top of the document resolved the problem and I
> don't
> mind editing the last question myself.
>
> However (and please don't take this as criticism because it's not; I'm
> just
> reporting what's happening and I may be expecting too much)... the macro
> bebops along fairly quickly for the first few questions. Then it slows to
> a
> crawl. I finally had to shut the computer down after an hour and it was
> about
> 1/3 of the way through. At this rate, it's going to take 3-4 hours (maybe
> more since it seems slower on each subsequent questions) to process the
> entire file, which is 212 pages long. I'm just reporting the behavior on
> the
> off chance there's some little tweak that can be made.
>
> I had to turn off Word's autosave and the computer's screen saver to keep
> things from locking up.
>
> Anyway, it appears that the macro fu