compile error: Loop without Do

S

Steved

Hello from Steved

Why am I getting an compile error: Loop without Do please.

Sub Testz()
Selection.HomeKey wdStory
Dim selstart As Long, selend As Long
With Selection.Find
Do While .Execute(FindText:="F [0-9]{1,}:[0-9]:[0-9]",
MatchWildcards:=True, Wrap:=wdFindContinue, Forward:=True) = True
Selection.Extend
'Once selection.extend is used then use'
selstart = Selection.Start
'then find your font and use the following lines:'
With Selection.Find.Font
.Size = 30
.Bold = True
selend = Selection.End
ActiveDocument.Range(selstart, selend).Select
'The above selects everything between the two search occurences
'Now deselect the items you want
Selection.MoveLeft Unit:=wdWord, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Collapse wdCollapseEnd
Loop
End Sub
 
J

Jonathan West

Steved said:
Hello from Steved

Why am I getting an compile error: Loop without Do please.

Sub Testz()
Selection.HomeKey wdStory
Dim selstart As Long, selend As Long
With Selection.Find
Do While .Execute(FindText:="F [0-9]{1,}:[0-9]:[0-9]",
MatchWildcards:=True, Wrap:=wdFindContinue, Forward:=True) = True
Selection.Extend
'Once selection.extend is used then use'
selstart = Selection.Start
'then find your font and use the following lines:'
With Selection.Find.Font
.Size = 30
.Bold = True
selend = Selection.End
ActiveDocument.Range(selstart, selend).Select
'The above selects everything between the two search occurences
'Now deselect the items you want
Selection.MoveLeft Unit:=wdWord, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Collapse wdCollapseEnd
Loop
End Sub

Because inside your Do loop you have a With statement and no matching End
With.

If you indent your code consistently, so that the code inside each control
structure (Do-Loop, For-Next, With-End With, etc) is indented relative to
the control commands, then problems like this will become instantly
apparent.

There is even a free tool to automatically indent code for you available
from here

Smart Indenter v3.5
http://www.oaltd.co.uk/Indenter/Default.htm


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
S

Steved

Hello Jonathan

End With
Loop
End With

Using the above I do not get any eerors but the macro does not do anything
ie using F8 to step thru it goes round and round the script and does nothing,
can you see what I am not got right in my script please.




Jonathan West said:
Steved said:
Hello from Steved

Why am I getting an compile error: Loop without Do please.

Sub Testz()
Selection.HomeKey wdStory
Dim selstart As Long, selend As Long
With Selection.Find
Do While .Execute(FindText:="F [0-9]{1,}:[0-9]:[0-9]",
MatchWildcards:=True, Wrap:=wdFindContinue, Forward:=True) = True
Selection.Extend
'Once selection.extend is used then use'
selstart = Selection.Start
'then find your font and use the following lines:'
With Selection.Find.Font
.Size = 30
.Bold = True
selend = Selection.End
ActiveDocument.Range(selstart, selend).Select
'The above selects everything between the two search occurences
'Now deselect the items you want
Selection.MoveLeft Unit:=wdWord, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Collapse wdCollapseEnd
Loop
End Sub

Because inside your Do loop you have a With statement and no matching End
With.

If you indent your code consistently, so that the code inside each control
structure (Do-Loop, For-Next, With-End With, etc) is indented relative to
the control commands, then problems like this will become instantly
apparent.

There is even a free tool to automatically indent code for you available
from here

Smart Indenter v3.5
http://www.oaltd.co.uk/Indenter/Default.htm


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
D

Doug Robbins - Word MVP

You have two With ... statements in your code and NO End With's

You need an End With for each With.

Heed what Jonathon said about indenting, it will make it much easier to get
things right



--
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

Steved said:
Hello Jonathan

End With
Loop
End With

Using the above I do not get any eerors but the macro does not do anything
ie using F8 to step thru it goes round and round the script and does
nothing,
can you see what I am not got right in my script please.




Jonathan West said:
Steved said:
Hello from Steved

Why am I getting an compile error: Loop without Do please.

Sub Testz()
Selection.HomeKey wdStory
Dim selstart As Long, selend As Long
With Selection.Find
Do While .Execute(FindText:="F [0-9]{1,}:[0-9]:[0-9]",
MatchWildcards:=True, Wrap:=wdFindContinue, Forward:=True) = True
Selection.Extend
'Once selection.extend is used then use'
selstart = Selection.Start
'then find your font and use the following lines:'
With Selection.Find.Font
.Size = 30
.Bold = True
selend = Selection.End
ActiveDocument.Range(selstart, selend).Select
'The above selects everything between the two search occurences
'Now deselect the items you want
Selection.MoveLeft Unit:=wdWord, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Collapse wdCollapseEnd
Loop
End Sub

Because inside your Do loop you have a With statement and no matching End
With.

If you indent your code consistently, so that the code inside each
control
structure (Do-Loop, For-Next, With-End With, etc) is indented relative to
the control commands, then problems like this will become instantly
apparent.

There is even a free tool to automatically indent code for you available
from here

Smart Indenter v3.5
http://www.oaltd.co.uk/Indenter/Default.htm


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
S

Steved

Thankyou I've did what Jonathon
but with no joy well,there has to be what I've done so I will go back and
have another go working threw using the F8 key.


Doug Robbins - Word MVP said:
You have two With ... statements in your code and NO End With's

You need an End With for each With.

Heed what Jonathon said about indenting, it will make it much easier to get
things right



--
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

Steved said:
Hello Jonathan

End With
Loop
End With

Using the above I do not get any eerors but the macro does not do anything
ie using F8 to step thru it goes round and round the script and does
nothing,
can you see what I am not got right in my script please.




Jonathan West said:
Hello from Steved

Why am I getting an compile error: Loop without Do please.

Sub Testz()
Selection.HomeKey wdStory
Dim selstart As Long, selend As Long
With Selection.Find
Do While .Execute(FindText:="F [0-9]{1,}:[0-9]:[0-9]",
MatchWildcards:=True, Wrap:=wdFindContinue, Forward:=True) = True
Selection.Extend
'Once selection.extend is used then use'
selstart = Selection.Start
'then find your font and use the following lines:'
With Selection.Find.Font
.Size = 30
.Bold = True
selend = Selection.End
ActiveDocument.Range(selstart, selend).Select
'The above selects everything between the two search occurences
'Now deselect the items you want
Selection.MoveLeft Unit:=wdWord, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Collapse wdCollapseEnd
Loop
End Sub


Because inside your Do loop you have a With statement and no matching End
With.

If you indent your code consistently, so that the code inside each
control
structure (Do-Loop, For-Next, With-End With, etc) is indented relative to
the control commands, then problems like this will become instantly
apparent.

There is even a free tool to automatically indent code for you available
from here

Smart Indenter v3.5
http://www.oaltd.co.uk/Indenter/Default.htm


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
J

Jonathan West

Steved said:
Hello Jonathan

End With
Loop
End With

Using the above I do not get any eerors but the macro does not do anything
ie using F8 to step thru it goes round and round the script and does
nothing,
can you see what I am not got right in my script please.

No, because you haven't said what the script *should* be doing.

--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
 
S

Steved

Hello Jonathon

I am asking the script to find F 0:0:0 then turn on extension then find the
next font 30. As the font 30 will be highlited go back 2 characters. Now just
delete the highlited.
 
J

Jonathan West

Steved said:
Hello Jonathon

I am asking the script to find F 0:0:0 then turn on extension then find
the
next font 30. As the font 30 will be highlited go back 2 characters. Now
just
delete the highlited.

When the .Execute line is executed, does the position of the selection
change in the document? If not, then you haven't got your Find set up right.
 

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