Find loop

P

Petra Liverani

Hi,

I have put together bits of code that will put a multiple select question into a particular format for loading online. Part of the code involves pasting the letter to the left of ~~~ against Answer=. Below is what the text looks like before and after. However, although I seem to have used the same code for a find loop that I've used elsewhere (I think it was Doug Robins who provided it for me) it does absolutely nothing in the case below. My code follows the before and after items below.

I would be most grateful for a solution.

Petra

BEFORE
Question 1
Body=blah blah
Answer=
Type=Multiple Select
Points=1
A. Nominated Client Cover
B. Carriers Legal Defence Cover
C. Fire and Theft only cover
D. Basic Cover
E. ~~~A, B and C
F. ~~~A, B and D

AFTER
Question 1
Body=blah blah
Answer=EF
Type=Multiple Select
Points=1
A. Nominated Client Cover
B. Carriers Legal Defence Cover
C. Fire and Theft only cover
D. Basic Cover
E. A, B and C
F. A, B and D


With Selection.Find
Do While .Execute(FindText:="~~~", Wrap:=wdFindStop, Forward:=True) = True

Selection.Delete Unit:=wdCharacter, Count:=1
Selection.HomeKey Unit:=wdLine
Selection.MoveRight Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Copy
Selection.MoveLeft Unit:=wdCharacter, Count:=1
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Answer="
.Replacement.Text = ""
.Forward = False
.Wrap = wdFindAsk
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Selection.EndKey Unit:=wdLine
Selection.Paste
Loop
End With
 
K

Klaus Linke

Hi Petra,

Should be safer to go to the top of the document before you start the macro,
since it only searches downwards (and only in the selection, if there is
one).

You could insert
Selection.HomeKey Unit:=wdStory
at the top of the macro.

Greetings,
Klaus
 
P

Petra Liverani

Hi Klaus,

I had this code at the top before but it didn't work. However, now the code
seems to work - don't know why it didn't before. Thanks for testing it and
proving that it does.

Regards,
Petra
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top