VBA .getElementbyID which has onchange event

Thilan

New Member
Joined
Jul 13, 2021
Messages
10
Office Version
  1. 2016
Platform
  1. Windows
I have the following code which automate data entry in web page.
but unable to complete the codes due to an error. below is given the current codes and website element where error occurs.

Codes:
Sub automateIE()

Dim IE As Object
Dim URL As String

Set IE = CreateObject("InternetExplorer.application")

IE.Visible = True
IE.navigate "IIS Windows Server"

Do While IE.Busy
Application.Wait DateAdd("S", 1, Now)
Loop
Set doc = IE.document
IE.document.getelementbyid("userid").Value = "xxxxx"
IE.document.getelementbyid("password64").Value = "xxxxxx"
IE.document.getelementbyid("company_code").Value = "xxxx"
IE.document.getelementbyid("branch_code").Value = "xxx"
IE.document.getelementbyid("login1").Click

Do While IE.Busy
Application.Wait DateAdd("S", 1, Now)
Loop

Set doc = IE.document
IE.document.getelementbyid("236").Click
IE.document.getelementbyid("4916").Click

Do While IE.Busy
Application.Wait DateAdd("S", 1, Now)
Loop

Set doc = IE.document
IE.document.getelementbyid("template_id").Value = "2631" - here is the error comes

End Sub

1648411415609.png



Here is the HTML from web site

1648411784927.png





kindly help me to short this out Thanks.
 

Attachments

  • 1648411409829.png
    1648411409829.png
    5.1 KB · Views: 46
  • 1648411568250.png
    1648411568250.png
    11.2 KB · Views: 38
I have no idea if this will work, and have no way of testing it, but looking at how it's been described in the onchange code, what if you tried:
VBA Code:
IE.Document.employee_form.employee_code.value = 2631
With or without quotation marks around 2631 - I'm not sure if that'll make a difference.
This assumes that the code on the page actually works. Though to be honest, if John_w's suggestion didn't work, I don't see that this should either.
I apologise for interrupting again, but I keep coming back to the onchange code you originally posted, and how it references Document.employee_form.employee_code. I'm not sure if you've had a chance to check it yet (and I appreciate that things were busy earlier), but given that this is triggered by an onchange event, may I ask - does the layout/controls/contents of the form you're trying to access change based on the selections you make in any of the comboboxes, listboxes, etc.?

If it does, I wonder whether the reason the element with the id employee_code can't be found is because it's Javascript-generated, and the relevant combination of selections has yet to be made? I don't claim to know any Javascript, but for what it's worth, here is the rabbit hole I went down:
  • I had a look for any JS files that looked remotely relevant that were linked in your code above, and form_actions.js seemed a likely candidate: https://oss.menaitechsystems.com/IM...napay/lib/form_actions.js?dontcash=4945446087
  • Clicking on the URL link provided in the HTML code above led to the JS code.
  • This JS code includes a function add_new(form) which in turn references an employee_form.
  • Searching for employee_form returns 20 references (though 42 in total, but half are duplicates) which appears to connect the types of employee form with different php files (e.g., vacations.php, financial_data.php, etc.).
  • From there, a search for employee_code returns a further 42 references, but this time, they are only connected with two php files - day_messages and anuual_converter.php (sic)
  • For anuual_converter.php, by way of example, it shows how the relevant parameters need to be constructed when being submitted to the php:
    JavaScript:
    window.open("../employees/anuual_converter.php?employee_code="+emp_code+"&index="+index,"anuual_converter","width=320,height=150,scrollbars=auto");
As I said, I know very little Javascript (and precisely zero php), so the above might be utterly irrelevant, and my apologies for wasting your time. But hopefully it might get you a little bit closer to what you're looking for?
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.

Forum statistics

Threads
1,223,965
Messages
6,175,660
Members
452,666
Latest member
AllexDee

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top