Thread: Reset on error
View Single Post
 
Old 09-23-2008, 08:15 PM
kiwichico kiwichico is offline
Novice
 
Join Date: Sep 2008
Posts: 1
kiwichico is on a distinguished road
Default Reset on error

Hi all,

I am trying to exit a loop or go to a certain place in the procedure once an error has been found. It works fine on the first iteration but the second time it doesn't recognise the on error commmand. Below is the piece of code. thanks in advance.

Sub FindTable()
startloop:

'Find first table
Selection.GoTo What:=wdGoToTable, Which:=wdGoToFirst, Count:=1, Name:=""

'If can not find any more tables exit loop
On Error GoTo endloop:
Selection.Tables(1).Cell(1, 1).Select

'If can not find row 2 column 3 go to local handler
On Error GoTo LocalHandler:
Selection.Tables(1).Cell(2, 3).Select

LocalHandler:

'Reset on error
On Error GoTo 0

GoTo startloop:
endloop:
End Sub
Reply With Quote