VBA Automation Development - Loop Error Handling

Asked

Viewed 333 times

-2

I am developing an automation in VBA that accesses a certain site and takes some information from it, however I’m having a problem in this.

The site (Santander - Benner) is very badly done, many parts were built in a way that appears to be amended with what had already done, IE, just added more features and did not configure the whole project.

Getting to the point, I wanted to know if you have any way to work with Goto error handling in loop form.

Example: while error occurs, do... or, is error, go back up to "x" line and do the procedure until you reach this checker again, if you have error again, redo and so on... I don’t know if you make it clear, but it’s loop Goto.

  • Hello, M. Marins. I formatted your text for better understanding and contribution of the participants.

  • Behold this answer. In which the If is used in conjunction with the GoTo. If everything occurs ok performs the functions, otherwise calls the function GetFolder and back to Inicio:

  • @danieltakeshi thanks for the link, the link example made me find a solution to this problem, using some research and seeing what you sent me, gave to assemble a solution

  • It would be good for you to add to the question the code you have for better understanding.

  • @Tony is on the bottom...

1 answer

2


After analyzing that, and some other research, I found a solution.

continue:
     'seta variavel operacao
     Set operacao = ie.document.getElementById("tsk_toolbar")

     'continua caso tenha erro
     On Error Resume Next

     'recebe o valor caso tenha dito erro
     va = Err.Number

     'verifica se teve erro, valor diferente que zero
     'caso tenha, retorna e seta novamente 
     If va <> 0 Then
          GoTo continue
     Else
          'nao faca nada
     End If

Just explaining again why that is, and not just treat the mistake itself. The site I’m working on is very bad for automation, and this error happens because the page takes too long to load, so not finding another way to solve this problem, I created this way, which solves my problem.

  • Another way is to use only: If va <> 0 Then GoTo continue, without the Else

Browser other questions tagged

You are not signed in. Login or sign up in order to post.