0

I am stuck at a specific point in coding VBA. Using VBA I am logging onto an Intranet portal which is a file management system and opening a series of dynamic web pages one after the other. Using VBA I am trying to get a checkbox element checked. Once this element is checked, all sub-elements appearing in a table below get checked automatically. After this I need to initiate download of all the selected files. However, I cannot get the checkbox element "checked".

Here is the HTML as it appears on the web-page. I cannot share the link as it is intranet and confidential.

Link to the HTML as I am not allowed to post images yet

Here is my VBA code:

Set inpute = objIE.Document.queryselector("div[id=gridx_Grid_2] div div div table tbody tr td span[aria-checked=false]")
inpute.setAttribute("aria-checked") = True
inpute.Click

When the above code is run, the "aria-selected" attribute changes to "true" in the HTML but Click has no effect on the checkbox. I have tried using the getElementbyClassName method and using Click after that to no avail.

Please help me out on this issue. Do let me know in case you need any other information.

  • First of all, a checkbox has no `click` event. On topic: Because the whole List of other checkboxes will be marked by marking the one in question, I'am pretty sure the one in question triggers a HTML event like `change` when you mark it manually. You must check which event it is and trigger it with VBA. You can look for the event with FireFox or Chrome, but not with the IE. Look here how to do that and how to handle with events: https://stackoverflow.com/questions/63294113/automate-ie-via-excel-to-fill-in-a-dropdown-and-continue/63299608#63299608 – Zwenn Mar 14 '21 at 15:12
  • Thank you Zwenn. I will try out the stuff on that link and let you know. – Prasad Athalye Mar 14 '21 at 16:26
  • Zwenn your link was a lifesaver when it came to checkbox thing. It worked perfectly. Many thanks for that ! I also learnt something new, the use of dispatchevent. However I am facing another issue now in the next step. I am unable to trigger any event for a dropdown list on the same page. Somehow I tried looking at the events in Chrome and there seems to be a click event on a span element and an invisible input element. But dispatchevent with click does not work on the elements. Any thoughts on why it may not be working or should I post a separate question / edit this question ?. – Prasad Athalye Mar 15 '21 at 05:05
  • From your last comment, it seems that you have solved the issue. I suggest that you can put it as an answer and mark it as an accepted answer. It can help other community members in future in similar kind of issues. Thanks for your understanding. – Yu Zhou Mar 15 '21 at 05:13

1 Answers1

1

This solution from Zwenn worked perfectly:

First of all, a checkbox has no click event. On topic: Because the whole List of other checkboxes will be marked by marking the one in question, I'am pretty sure the one in question triggers a HTML event like change when you mark it manually. You must check which event it is and trigger it with VBA. You can look for the event with FireFox or Chrome, but not with the IE. Look here how to do that and how to handle with events:

Automate IE via Excel to fill in a dropdown and continue

– Zwenn 14 hours ago