El código de Visual Basic salta a una ubicación aparentemente aleatoria

I have a Visual Basic program in Excel which opens Word documents and copies information from Word into Excel. At its heart is a for loop which goes through each table in one document. Inside the for loop is a call to a function to process that table:

For nCurrentTable = 1 To nTotalTable
    ' Process each table in Word document, one at a time.
    Call Process_One_Table(nCurrentTable, nTotalTable, vDocName)
Next nCurrentTable

The n variables are Longs, vDocName is a Variant.

Why is the script exiting that function to go to the next at the end of the for loop? It has happened at various points. Right now it occurs after (code from deep in Process_One_Table):

Cells(1, nColumn).Select

It also occurred after I misused an assignment, assigning a String to a Long (which I've now corrected).

preguntado el 01 de febrero de 12 a las 22:02

1 Respuestas

An On Error Resume Next in the calling procedure is the most likely cause of this. If the called procedure raises an error, execution resumes at the next line of the calling procedure.

Respondido 02 Feb 12, 02:02

Additionally, there would be no error handler (or an On Error Goto 0 statement) in the llamado procedimiento. - mwolfe02

@mwolfe02 Indeed, either that or the called procedure's error handler itself raises an error ;-) - Neil

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.