|
-
January 23rd, 2003, 07:38 PM
#1
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?
-
January 23rd, 2003, 08:02 PM
#2
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
-
January 24th, 2003, 03:25 AM
#3
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
-
January 24th, 2003, 03:51 AM
#4
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
-
January 24th, 2003, 04:09 AM
#5
Thank you Luthv thats exactly what I need.
Very grateful to you
Gem_man
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|