-
Exiting a For Next Loop
Hey chaps and chapess's I know this is really basic stuff for you but assistance would be most appreciated.
I have set up a For Next loop that cuts and pastes tables another place in a word 2000 document.
Since the number of tables present varies (anything from 5 to 50) I have set the For value at 50
My problem is that I cannot figure out how to get the routine to Exit the loop when the error message appears stating that I have "run out of files"
Is there a simple line I can add?
Thank you in advance.
Gem_man
PS If this is an irritatingly simple question can anyone suggest a forum that will be hapy to answer my numerous ridiculously simple queries?
:confused:
-
For i = o to 50
'your code
if ....then
Exit For
end if
next i
If that is what you are getting at (?) The Exit For line will break the loop. Cheers
DA
-
Well sort of.
The problem is that the number of tables that I move, is not fixed.
Unless I can get the code to count the number of tables present in the document, I cant see how I could use the If Then statement.
Is there no code line that basically says "if an error occurs then exit the loop"?
Failing that, is it possible for VB to be able to count how many tables are in a document?
Then I could just set the For figure to this.
Thank you for your help
Adrian
-
To get table count in Word VBA use the tables property
Selection.Document.Tables.Count
for error traping in a loop:
on error resume next
for i=1 to 50
...do something
if err.number <> 0 then
err.clear
exit for
end if
next
-
Thank you Luthv thats exactly what I need.
Very grateful to you
Gem_man