How can I skip commands on excel VBA under this specific situation?

46 views Asked by At

I created a code on excel VBA that can seacrch and send automated text messages to different contacts on the whatsapp web platform. However, the code starts failling when it searches for a contact but it doesnt show up, it proceeds with the loop instead of skipping to the relevant part of the loop.

Because it doesnt skip to the relevant part of the loop it starts typing in the wrong searchboxes and clickin gon the wrong buttons ruinning the objective.

I have the code below, does anyone have any idea of what command or function could I add and how to add it in order to fix this issue and have excel skip to the right part of the code? (im extremely new to coding):

'Locate the contact and send message

With Application
     .SendKeys "{TAB}"
     .SendKeys "{TAB}"
     .SendKeys "{TAB}"
     .SendKeys "{TAB}"
     .SendKeys "{TAB}"
     .SendKeys "{TAB}"
     .SendKeys "{TAB}"
     .SendKeys "{TAB}"
     .Wait Now + TimeValue("00:00:02")
     .SendKeys Contact
     .Wait Now + TimeValue("00:00:02")
     .SendKeys "~"
     .Wait Now + TimeValue("00:00:02")
     .SendKeys "~"
     .SendKeys Mensagem
     .Wait Now + TimeValue("00:00:02")
     .SendKeys "~"

'Next contact
     .SendKeys "{TAB}"

after the programe searches for the contact if there is no result id like it to skip to the next contact. Can anyone help me?

0

There are 0 answers