Selecting a HTML button in Excel VBA that does not have an id
Been working on this issue for a day now. I have a webform that you have 1 set of standard data, and then you enter line items for a purchase requisition; I am trying to enter all data in Excel and use VBA to transfer it to the site. I am getting stuck at how to "update part" (the text on the button that I need to click to add another line item on the webpage). I have also tried the send key method to Shift Tab into the correct location (just normal shifting runs into an error with one of the fields). I am fine with any solution working, this is my first attempt at linking Excel to HTML so it's been fun.
From what I can find the button does not have an id so I have not been successful in calling it.
Here is my code (with the web url deleted):
Sub Login_2_Website()
Dim oHTML_Element As IHTMLElement
Dim oHTML_Element1 As IHTMLElement
Dim sURL As String
Dim aURL As String
Dim nodeList As Object
On Error GoTo Err_Clear
sURL = URL Can't be Shared
oBrowser.Silent = True
oBrowser.timeout = 60
oBrowser.Navigate sURL
oBrowser.Visible = True
Do
' Wait till the Browser is loaded
Loop Until oBrowser.ReadyState = READYSTATE_COMPLETE
Set HTMLDoc = oBrowser.Document
Set nodeList = HTMLDoc.querySelectorAll("a[onlick*='UpdatePartRow']")
HTMLDoc.all.UserName.Value = ThisWorkbook.Sheets("sheet1").Range("I1")
HTMLDoc.all.Password.Value = ThisWorkbook.Sheets("sheet1").Range("I2")
For Each oHTML_Element In HTMLDoc.getElementsByTagName("input")
If oHTML_Element.Type = "submit" Then oHTML_Element.Click: Exit For
HTMLDoc.all.reason.Value = ThisWorkbook.Sheets("sheet1").Range("B1") ' selects the reason for the requisition
HTMLDoc.all.Comments.Value = ThisWorkbook.Sheets("sheet1").Range("B2") ' selects the comments to purchasing
HTMLDoc.forms("_PurchaseRequisition").getElementsByTagName("select")("RequiredMonth").Value = ThisWorkbook.Sheets("sheet1").Range("B3")
HTMLDoc.forms("_PurchaseRequisition").FireEvent ("onchange")
HTMLDoc.forms("_PurchaseRequisition").getElementsByTagName("select")("RequiredDay").Value = ThisWorkbook.Sheets("sheet1").Range("B4")
HTMLDoc.forms("_PurchaseRequisition").FireEvent ("onchange")
HTMLDoc.forms("_PurchaseRequisition").getElementsByTagName("select")("RequiredYear").Value = ThisWorkbook.Sheets("sheet1").Range("B5")
HTMLDoc.forms("_PurchaseRequisition").FireEvent ("onchange")
HTMLDoc.forms("_PurchaseRequisition").getElementsByTagName("select")("CommodityMain").Value = ThisWorkbook.Sheets("sheet1").Range("B9")
HTMLDoc.forms("_PurchaseRequisition").FireEvent ("onchange") 'Selects the commodity group
HTMLDoc.all.Quantity.Value = ThisWorkbook.Sheets("sheet1").Range("B11")
HTMLDoc.all.Description.Value = ThisWorkbook.Sheets("sheet1").Range("B12")
HTMLDoc.all.ChargedDepartment.Value = ThisWorkbook.Sheets("sheet1").Range("B13")
HTMLDoc.all.SubJobNumber.Value = ThisWorkbook.Sheets("sheet1").Range("B14")
HTMLDoc.all.AccountNumber.Value = ThisWorkbook.Sheets("sheet1").Range("B15")
HTMLDoc.all.UnitPrice.Value = ThisWorkbook.Sheets("sheet1").Range("B16")
HTMLDoc.all.CommodityMainSub.Value = ThisWorkbook.Sheets("sheet1").Range("B17")
Set nodeList = HTMLDoc.querySelectorAll("a[onlick*='UpdatePartRow']")
nodeList.Item(0).Click
nodeList.Item(0).FireEvent "onclick"
Next
' oBrowser.Refresh ' Refresh If Needed
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub
For the login portion I modified code from: http://vbadud.blogspot.com/2009/08/how-to-login-to-website-using-vba.html#ZiqYAtAQMHzl7x1k.99
That works perfectly, so does entering the fields.
The segment of HTML that is associated with this button is:
<a onclick="UpdatePartRow();
chkKeepSubmitPR();
return false;" href=""></a>
<a onclick="var doc = window.document.forms[0];
UpdatePartRow();
chkKeepSubmitPR();
if (doc.OrgMatrixYes.value == "Y")
VerifyDeptOrgMatrix();
return false;" href=""><img src="/Web/purchreq.nsf/UpdatePart.gif?OpenImageResource" width="72" height="25" border="0"></a>
I am taking this on because this system is a pain. I could just have multiple macros and have the user hit the button between each line item, but I want to try to offer a full solution. I am a mechanical engineer by trade and my coding experience is limited to what I have picked up on making tools to ease my job. Any help or suggestions would be super helpful. If there is more info needed, please let me know and I can try to help anyway I can. Thank you!
Update: I have tried (See Code) to make the changes that have been suggested. I am still a fairly complete newbie when it comes to coding, so please bear with me and thank you for trying to teach me!
html excel vba excel-vba web-scraping
add a comment |
Been working on this issue for a day now. I have a webform that you have 1 set of standard data, and then you enter line items for a purchase requisition; I am trying to enter all data in Excel and use VBA to transfer it to the site. I am getting stuck at how to "update part" (the text on the button that I need to click to add another line item on the webpage). I have also tried the send key method to Shift Tab into the correct location (just normal shifting runs into an error with one of the fields). I am fine with any solution working, this is my first attempt at linking Excel to HTML so it's been fun.
From what I can find the button does not have an id so I have not been successful in calling it.
Here is my code (with the web url deleted):
Sub Login_2_Website()
Dim oHTML_Element As IHTMLElement
Dim oHTML_Element1 As IHTMLElement
Dim sURL As String
Dim aURL As String
Dim nodeList As Object
On Error GoTo Err_Clear
sURL = URL Can't be Shared
oBrowser.Silent = True
oBrowser.timeout = 60
oBrowser.Navigate sURL
oBrowser.Visible = True
Do
' Wait till the Browser is loaded
Loop Until oBrowser.ReadyState = READYSTATE_COMPLETE
Set HTMLDoc = oBrowser.Document
Set nodeList = HTMLDoc.querySelectorAll("a[onlick*='UpdatePartRow']")
HTMLDoc.all.UserName.Value = ThisWorkbook.Sheets("sheet1").Range("I1")
HTMLDoc.all.Password.Value = ThisWorkbook.Sheets("sheet1").Range("I2")
For Each oHTML_Element In HTMLDoc.getElementsByTagName("input")
If oHTML_Element.Type = "submit" Then oHTML_Element.Click: Exit For
HTMLDoc.all.reason.Value = ThisWorkbook.Sheets("sheet1").Range("B1") ' selects the reason for the requisition
HTMLDoc.all.Comments.Value = ThisWorkbook.Sheets("sheet1").Range("B2") ' selects the comments to purchasing
HTMLDoc.forms("_PurchaseRequisition").getElementsByTagName("select")("RequiredMonth").Value = ThisWorkbook.Sheets("sheet1").Range("B3")
HTMLDoc.forms("_PurchaseRequisition").FireEvent ("onchange")
HTMLDoc.forms("_PurchaseRequisition").getElementsByTagName("select")("RequiredDay").Value = ThisWorkbook.Sheets("sheet1").Range("B4")
HTMLDoc.forms("_PurchaseRequisition").FireEvent ("onchange")
HTMLDoc.forms("_PurchaseRequisition").getElementsByTagName("select")("RequiredYear").Value = ThisWorkbook.Sheets("sheet1").Range("B5")
HTMLDoc.forms("_PurchaseRequisition").FireEvent ("onchange")
HTMLDoc.forms("_PurchaseRequisition").getElementsByTagName("select")("CommodityMain").Value = ThisWorkbook.Sheets("sheet1").Range("B9")
HTMLDoc.forms("_PurchaseRequisition").FireEvent ("onchange") 'Selects the commodity group
HTMLDoc.all.Quantity.Value = ThisWorkbook.Sheets("sheet1").Range("B11")
HTMLDoc.all.Description.Value = ThisWorkbook.Sheets("sheet1").Range("B12")
HTMLDoc.all.ChargedDepartment.Value = ThisWorkbook.Sheets("sheet1").Range("B13")
HTMLDoc.all.SubJobNumber.Value = ThisWorkbook.Sheets("sheet1").Range("B14")
HTMLDoc.all.AccountNumber.Value = ThisWorkbook.Sheets("sheet1").Range("B15")
HTMLDoc.all.UnitPrice.Value = ThisWorkbook.Sheets("sheet1").Range("B16")
HTMLDoc.all.CommodityMainSub.Value = ThisWorkbook.Sheets("sheet1").Range("B17")
Set nodeList = HTMLDoc.querySelectorAll("a[onlick*='UpdatePartRow']")
nodeList.Item(0).Click
nodeList.Item(0).FireEvent "onclick"
Next
' oBrowser.Refresh ' Refresh If Needed
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub
For the login portion I modified code from: http://vbadud.blogspot.com/2009/08/how-to-login-to-website-using-vba.html#ZiqYAtAQMHzl7x1k.99
That works perfectly, so does entering the fields.
The segment of HTML that is associated with this button is:
<a onclick="UpdatePartRow();
chkKeepSubmitPR();
return false;" href=""></a>
<a onclick="var doc = window.document.forms[0];
UpdatePartRow();
chkKeepSubmitPR();
if (doc.OrgMatrixYes.value == "Y")
VerifyDeptOrgMatrix();
return false;" href=""><img src="/Web/purchreq.nsf/UpdatePart.gif?OpenImageResource" width="72" height="25" border="0"></a>
I am taking this on because this system is a pain. I could just have multiple macros and have the user hit the button between each line item, but I want to try to offer a full solution. I am a mechanical engineer by trade and my coding experience is limited to what I have picked up on making tools to ease my job. Any help or suggestions would be super helpful. If there is more info needed, please let me know and I can try to help anyway I can. Thank you!
Update: I have tried (See Code) to make the changes that have been suggested. I am still a fairly complete newbie when it comes to coding, so please bear with me and thank you for trying to teach me!
html excel vba excel-vba web-scraping
1
Are you sure it's a button, it has an <a> tag. You could try to get the item, and then invoke its click method using.fireevent("click")
– Nathan_Sav
Nov 13 '18 at 13:02
Can you provide an URL?
– QHarr
Nov 13 '18 at 13:16
@QHarr, it is a company specific URL that has data on purchasing projects, for several reasons I cannot share it.
– Da_Bushwacker
Nov 14 '18 at 14:32
ok... well give the below a try and let me know :-)
– QHarr
Nov 14 '18 at 14:37
add a comment |
Been working on this issue for a day now. I have a webform that you have 1 set of standard data, and then you enter line items for a purchase requisition; I am trying to enter all data in Excel and use VBA to transfer it to the site. I am getting stuck at how to "update part" (the text on the button that I need to click to add another line item on the webpage). I have also tried the send key method to Shift Tab into the correct location (just normal shifting runs into an error with one of the fields). I am fine with any solution working, this is my first attempt at linking Excel to HTML so it's been fun.
From what I can find the button does not have an id so I have not been successful in calling it.
Here is my code (with the web url deleted):
Sub Login_2_Website()
Dim oHTML_Element As IHTMLElement
Dim oHTML_Element1 As IHTMLElement
Dim sURL As String
Dim aURL As String
Dim nodeList As Object
On Error GoTo Err_Clear
sURL = URL Can't be Shared
oBrowser.Silent = True
oBrowser.timeout = 60
oBrowser.Navigate sURL
oBrowser.Visible = True
Do
' Wait till the Browser is loaded
Loop Until oBrowser.ReadyState = READYSTATE_COMPLETE
Set HTMLDoc = oBrowser.Document
Set nodeList = HTMLDoc.querySelectorAll("a[onlick*='UpdatePartRow']")
HTMLDoc.all.UserName.Value = ThisWorkbook.Sheets("sheet1").Range("I1")
HTMLDoc.all.Password.Value = ThisWorkbook.Sheets("sheet1").Range("I2")
For Each oHTML_Element In HTMLDoc.getElementsByTagName("input")
If oHTML_Element.Type = "submit" Then oHTML_Element.Click: Exit For
HTMLDoc.all.reason.Value = ThisWorkbook.Sheets("sheet1").Range("B1") ' selects the reason for the requisition
HTMLDoc.all.Comments.Value = ThisWorkbook.Sheets("sheet1").Range("B2") ' selects the comments to purchasing
HTMLDoc.forms("_PurchaseRequisition").getElementsByTagName("select")("RequiredMonth").Value = ThisWorkbook.Sheets("sheet1").Range("B3")
HTMLDoc.forms("_PurchaseRequisition").FireEvent ("onchange")
HTMLDoc.forms("_PurchaseRequisition").getElementsByTagName("select")("RequiredDay").Value = ThisWorkbook.Sheets("sheet1").Range("B4")
HTMLDoc.forms("_PurchaseRequisition").FireEvent ("onchange")
HTMLDoc.forms("_PurchaseRequisition").getElementsByTagName("select")("RequiredYear").Value = ThisWorkbook.Sheets("sheet1").Range("B5")
HTMLDoc.forms("_PurchaseRequisition").FireEvent ("onchange")
HTMLDoc.forms("_PurchaseRequisition").getElementsByTagName("select")("CommodityMain").Value = ThisWorkbook.Sheets("sheet1").Range("B9")
HTMLDoc.forms("_PurchaseRequisition").FireEvent ("onchange") 'Selects the commodity group
HTMLDoc.all.Quantity.Value = ThisWorkbook.Sheets("sheet1").Range("B11")
HTMLDoc.all.Description.Value = ThisWorkbook.Sheets("sheet1").Range("B12")
HTMLDoc.all.ChargedDepartment.Value = ThisWorkbook.Sheets("sheet1").Range("B13")
HTMLDoc.all.SubJobNumber.Value = ThisWorkbook.Sheets("sheet1").Range("B14")
HTMLDoc.all.AccountNumber.Value = ThisWorkbook.Sheets("sheet1").Range("B15")
HTMLDoc.all.UnitPrice.Value = ThisWorkbook.Sheets("sheet1").Range("B16")
HTMLDoc.all.CommodityMainSub.Value = ThisWorkbook.Sheets("sheet1").Range("B17")
Set nodeList = HTMLDoc.querySelectorAll("a[onlick*='UpdatePartRow']")
nodeList.Item(0).Click
nodeList.Item(0).FireEvent "onclick"
Next
' oBrowser.Refresh ' Refresh If Needed
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub
For the login portion I modified code from: http://vbadud.blogspot.com/2009/08/how-to-login-to-website-using-vba.html#ZiqYAtAQMHzl7x1k.99
That works perfectly, so does entering the fields.
The segment of HTML that is associated with this button is:
<a onclick="UpdatePartRow();
chkKeepSubmitPR();
return false;" href=""></a>
<a onclick="var doc = window.document.forms[0];
UpdatePartRow();
chkKeepSubmitPR();
if (doc.OrgMatrixYes.value == "Y")
VerifyDeptOrgMatrix();
return false;" href=""><img src="/Web/purchreq.nsf/UpdatePart.gif?OpenImageResource" width="72" height="25" border="0"></a>
I am taking this on because this system is a pain. I could just have multiple macros and have the user hit the button between each line item, but I want to try to offer a full solution. I am a mechanical engineer by trade and my coding experience is limited to what I have picked up on making tools to ease my job. Any help or suggestions would be super helpful. If there is more info needed, please let me know and I can try to help anyway I can. Thank you!
Update: I have tried (See Code) to make the changes that have been suggested. I am still a fairly complete newbie when it comes to coding, so please bear with me and thank you for trying to teach me!
html excel vba excel-vba web-scraping
Been working on this issue for a day now. I have a webform that you have 1 set of standard data, and then you enter line items for a purchase requisition; I am trying to enter all data in Excel and use VBA to transfer it to the site. I am getting stuck at how to "update part" (the text on the button that I need to click to add another line item on the webpage). I have also tried the send key method to Shift Tab into the correct location (just normal shifting runs into an error with one of the fields). I am fine with any solution working, this is my first attempt at linking Excel to HTML so it's been fun.
From what I can find the button does not have an id so I have not been successful in calling it.
Here is my code (with the web url deleted):
Sub Login_2_Website()
Dim oHTML_Element As IHTMLElement
Dim oHTML_Element1 As IHTMLElement
Dim sURL As String
Dim aURL As String
Dim nodeList As Object
On Error GoTo Err_Clear
sURL = URL Can't be Shared
oBrowser.Silent = True
oBrowser.timeout = 60
oBrowser.Navigate sURL
oBrowser.Visible = True
Do
' Wait till the Browser is loaded
Loop Until oBrowser.ReadyState = READYSTATE_COMPLETE
Set HTMLDoc = oBrowser.Document
Set nodeList = HTMLDoc.querySelectorAll("a[onlick*='UpdatePartRow']")
HTMLDoc.all.UserName.Value = ThisWorkbook.Sheets("sheet1").Range("I1")
HTMLDoc.all.Password.Value = ThisWorkbook.Sheets("sheet1").Range("I2")
For Each oHTML_Element In HTMLDoc.getElementsByTagName("input")
If oHTML_Element.Type = "submit" Then oHTML_Element.Click: Exit For
HTMLDoc.all.reason.Value = ThisWorkbook.Sheets("sheet1").Range("B1") ' selects the reason for the requisition
HTMLDoc.all.Comments.Value = ThisWorkbook.Sheets("sheet1").Range("B2") ' selects the comments to purchasing
HTMLDoc.forms("_PurchaseRequisition").getElementsByTagName("select")("RequiredMonth").Value = ThisWorkbook.Sheets("sheet1").Range("B3")
HTMLDoc.forms("_PurchaseRequisition").FireEvent ("onchange")
HTMLDoc.forms("_PurchaseRequisition").getElementsByTagName("select")("RequiredDay").Value = ThisWorkbook.Sheets("sheet1").Range("B4")
HTMLDoc.forms("_PurchaseRequisition").FireEvent ("onchange")
HTMLDoc.forms("_PurchaseRequisition").getElementsByTagName("select")("RequiredYear").Value = ThisWorkbook.Sheets("sheet1").Range("B5")
HTMLDoc.forms("_PurchaseRequisition").FireEvent ("onchange")
HTMLDoc.forms("_PurchaseRequisition").getElementsByTagName("select")("CommodityMain").Value = ThisWorkbook.Sheets("sheet1").Range("B9")
HTMLDoc.forms("_PurchaseRequisition").FireEvent ("onchange") 'Selects the commodity group
HTMLDoc.all.Quantity.Value = ThisWorkbook.Sheets("sheet1").Range("B11")
HTMLDoc.all.Description.Value = ThisWorkbook.Sheets("sheet1").Range("B12")
HTMLDoc.all.ChargedDepartment.Value = ThisWorkbook.Sheets("sheet1").Range("B13")
HTMLDoc.all.SubJobNumber.Value = ThisWorkbook.Sheets("sheet1").Range("B14")
HTMLDoc.all.AccountNumber.Value = ThisWorkbook.Sheets("sheet1").Range("B15")
HTMLDoc.all.UnitPrice.Value = ThisWorkbook.Sheets("sheet1").Range("B16")
HTMLDoc.all.CommodityMainSub.Value = ThisWorkbook.Sheets("sheet1").Range("B17")
Set nodeList = HTMLDoc.querySelectorAll("a[onlick*='UpdatePartRow']")
nodeList.Item(0).Click
nodeList.Item(0).FireEvent "onclick"
Next
' oBrowser.Refresh ' Refresh If Needed
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub
For the login portion I modified code from: http://vbadud.blogspot.com/2009/08/how-to-login-to-website-using-vba.html#ZiqYAtAQMHzl7x1k.99
That works perfectly, so does entering the fields.
The segment of HTML that is associated with this button is:
<a onclick="UpdatePartRow();
chkKeepSubmitPR();
return false;" href=""></a>
<a onclick="var doc = window.document.forms[0];
UpdatePartRow();
chkKeepSubmitPR();
if (doc.OrgMatrixYes.value == "Y")
VerifyDeptOrgMatrix();
return false;" href=""><img src="/Web/purchreq.nsf/UpdatePart.gif?OpenImageResource" width="72" height="25" border="0"></a>
I am taking this on because this system is a pain. I could just have multiple macros and have the user hit the button between each line item, but I want to try to offer a full solution. I am a mechanical engineer by trade and my coding experience is limited to what I have picked up on making tools to ease my job. Any help or suggestions would be super helpful. If there is more info needed, please let me know and I can try to help anyway I can. Thank you!
Update: I have tried (See Code) to make the changes that have been suggested. I am still a fairly complete newbie when it comes to coding, so please bear with me and thank you for trying to teach me!
html excel vba excel-vba web-scraping
html excel vba excel-vba web-scraping
edited Nov 16 '18 at 16:44
doppelgreener
4,42163252
4,42163252
asked Nov 13 '18 at 12:56
Da_BushwackerDa_Bushwacker
83
83
1
Are you sure it's a button, it has an <a> tag. You could try to get the item, and then invoke its click method using.fireevent("click")
– Nathan_Sav
Nov 13 '18 at 13:02
Can you provide an URL?
– QHarr
Nov 13 '18 at 13:16
@QHarr, it is a company specific URL that has data on purchasing projects, for several reasons I cannot share it.
– Da_Bushwacker
Nov 14 '18 at 14:32
ok... well give the below a try and let me know :-)
– QHarr
Nov 14 '18 at 14:37
add a comment |
1
Are you sure it's a button, it has an <a> tag. You could try to get the item, and then invoke its click method using.fireevent("click")
– Nathan_Sav
Nov 13 '18 at 13:02
Can you provide an URL?
– QHarr
Nov 13 '18 at 13:16
@QHarr, it is a company specific URL that has data on purchasing projects, for several reasons I cannot share it.
– Da_Bushwacker
Nov 14 '18 at 14:32
ok... well give the below a try and let me know :-)
– QHarr
Nov 14 '18 at 14:37
1
1
Are you sure it's a button, it has an <a> tag. You could try to get the item, and then invoke its click method using
.fireevent("click")
– Nathan_Sav
Nov 13 '18 at 13:02
Are you sure it's a button, it has an <a> tag. You could try to get the item, and then invoke its click method using
.fireevent("click")
– Nathan_Sav
Nov 13 '18 at 13:02
Can you provide an URL?
– QHarr
Nov 13 '18 at 13:16
Can you provide an URL?
– QHarr
Nov 13 '18 at 13:16
@QHarr, it is a company specific URL that has data on purchasing projects, for several reasons I cannot share it.
– Da_Bushwacker
Nov 14 '18 at 14:32
@QHarr, it is a company specific URL that has data on purchasing projects, for several reasons I cannot share it.
– Da_Bushwacker
Nov 14 '18 at 14:32
ok... well give the below a try and let me know :-)
– QHarr
Nov 14 '18 at 14:37
ok... well give the below a try and let me know :-)
– QHarr
Nov 14 '18 at 14:37
add a comment |
1 Answer
1
active
oldest
votes
You have two a
tag elements there with an onclick
You can get both with attribute = value CSS selector using "*"
contains operator to search for a substring in the attribute value
a[onclick*='UpdatePartRow']
You can grab both with querySelectorAll
method of HTMLDocument object
Dim nodeList As Object
Set nodeList = HTMLDoc.querySelectorAll("a[onclick*='UpdatePartRow']")
The two matches, for your sample, are as follows:
index 0
<a onclick="UpdatePartRow(); chkKeepSubmitPR(); return false;" href="">
index 1
<a onclick="var doc = window.document.forms[0]; UpdatePartRow(); chkKeepSubmitPR(); if (doc.OrgMatrixYes.value == "Y") VerifyDeptOrgMatrix(); return false;" href="">
You can access the nodeList by index e.g.
nodeList.item(0).Click
nodeList.item(0).FireEvent "onclick"
So I modified the VBA code to include: 'Dim nodeList As Object Set nodeList = HTMLDoc.querySelectorAll("a[onclick*='UpdatePartRow']")' and I set the node list: HTMLDoc.all.CommodityMainSub.Value = ThisWorkbook.Sheets("sheet1").Range("B17") Set nodeList = HTMLDoc.querySelectorAll("a[onlick*='UpdatePartRow']") nodeList.Item(0).Click nodeList.Item(0).FireEvent "onclick" It is still not giving me the result I am hoping for of "clicking" on the button. Am I messing something up? thank you for the help so far!
– Da_Bushwacker
Nov 14 '18 at 14:53
Any errors? And did you try replacing the 0 with 1 throughout?
– QHarr
Nov 14 '18 at 15:04
It ran through the code in VBA with no errors popping up in VBA/Excel. I have tried changing the 0 to 1. I have also tried to change it to chkKeepSubmitPR instead of the UpdatePartRow.
– Da_Bushwacker
Nov 14 '18 at 15:18
I think I just found it! But I made the website crash! nodeList.item(0).FireEvent "onclick" needed to be nodeList.item(0).FireEvent ("onclick"). The webpage is now giving me an error saying "Quantity must be greater than zero, unable to complete request!". So now I have to figure out why it is doing that and how I can fix that. That you so much @QHarr. I will let you know if I have more questions or the completed code once I solve it!
– Da_Bushwacker
Nov 14 '18 at 15:20
You shouldn't need () around "onclick" AFAIK. But good luck! Just don't try For Each loop with nodeList or inspecting in locals window - that will crash Excel.
– QHarr
Nov 14 '18 at 15:58
|
show 3 more comments
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53281519%2fselecting-a-html-button-in-excel-vba-that-does-not-have-an-id%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have two a
tag elements there with an onclick
You can get both with attribute = value CSS selector using "*"
contains operator to search for a substring in the attribute value
a[onclick*='UpdatePartRow']
You can grab both with querySelectorAll
method of HTMLDocument object
Dim nodeList As Object
Set nodeList = HTMLDoc.querySelectorAll("a[onclick*='UpdatePartRow']")
The two matches, for your sample, are as follows:
index 0
<a onclick="UpdatePartRow(); chkKeepSubmitPR(); return false;" href="">
index 1
<a onclick="var doc = window.document.forms[0]; UpdatePartRow(); chkKeepSubmitPR(); if (doc.OrgMatrixYes.value == "Y") VerifyDeptOrgMatrix(); return false;" href="">
You can access the nodeList by index e.g.
nodeList.item(0).Click
nodeList.item(0).FireEvent "onclick"
So I modified the VBA code to include: 'Dim nodeList As Object Set nodeList = HTMLDoc.querySelectorAll("a[onclick*='UpdatePartRow']")' and I set the node list: HTMLDoc.all.CommodityMainSub.Value = ThisWorkbook.Sheets("sheet1").Range("B17") Set nodeList = HTMLDoc.querySelectorAll("a[onlick*='UpdatePartRow']") nodeList.Item(0).Click nodeList.Item(0).FireEvent "onclick" It is still not giving me the result I am hoping for of "clicking" on the button. Am I messing something up? thank you for the help so far!
– Da_Bushwacker
Nov 14 '18 at 14:53
Any errors? And did you try replacing the 0 with 1 throughout?
– QHarr
Nov 14 '18 at 15:04
It ran through the code in VBA with no errors popping up in VBA/Excel. I have tried changing the 0 to 1. I have also tried to change it to chkKeepSubmitPR instead of the UpdatePartRow.
– Da_Bushwacker
Nov 14 '18 at 15:18
I think I just found it! But I made the website crash! nodeList.item(0).FireEvent "onclick" needed to be nodeList.item(0).FireEvent ("onclick"). The webpage is now giving me an error saying "Quantity must be greater than zero, unable to complete request!". So now I have to figure out why it is doing that and how I can fix that. That you so much @QHarr. I will let you know if I have more questions or the completed code once I solve it!
– Da_Bushwacker
Nov 14 '18 at 15:20
You shouldn't need () around "onclick" AFAIK. But good luck! Just don't try For Each loop with nodeList or inspecting in locals window - that will crash Excel.
– QHarr
Nov 14 '18 at 15:58
|
show 3 more comments
You have two a
tag elements there with an onclick
You can get both with attribute = value CSS selector using "*"
contains operator to search for a substring in the attribute value
a[onclick*='UpdatePartRow']
You can grab both with querySelectorAll
method of HTMLDocument object
Dim nodeList As Object
Set nodeList = HTMLDoc.querySelectorAll("a[onclick*='UpdatePartRow']")
The two matches, for your sample, are as follows:
index 0
<a onclick="UpdatePartRow(); chkKeepSubmitPR(); return false;" href="">
index 1
<a onclick="var doc = window.document.forms[0]; UpdatePartRow(); chkKeepSubmitPR(); if (doc.OrgMatrixYes.value == "Y") VerifyDeptOrgMatrix(); return false;" href="">
You can access the nodeList by index e.g.
nodeList.item(0).Click
nodeList.item(0).FireEvent "onclick"
So I modified the VBA code to include: 'Dim nodeList As Object Set nodeList = HTMLDoc.querySelectorAll("a[onclick*='UpdatePartRow']")' and I set the node list: HTMLDoc.all.CommodityMainSub.Value = ThisWorkbook.Sheets("sheet1").Range("B17") Set nodeList = HTMLDoc.querySelectorAll("a[onlick*='UpdatePartRow']") nodeList.Item(0).Click nodeList.Item(0).FireEvent "onclick" It is still not giving me the result I am hoping for of "clicking" on the button. Am I messing something up? thank you for the help so far!
– Da_Bushwacker
Nov 14 '18 at 14:53
Any errors? And did you try replacing the 0 with 1 throughout?
– QHarr
Nov 14 '18 at 15:04
It ran through the code in VBA with no errors popping up in VBA/Excel. I have tried changing the 0 to 1. I have also tried to change it to chkKeepSubmitPR instead of the UpdatePartRow.
– Da_Bushwacker
Nov 14 '18 at 15:18
I think I just found it! But I made the website crash! nodeList.item(0).FireEvent "onclick" needed to be nodeList.item(0).FireEvent ("onclick"). The webpage is now giving me an error saying "Quantity must be greater than zero, unable to complete request!". So now I have to figure out why it is doing that and how I can fix that. That you so much @QHarr. I will let you know if I have more questions or the completed code once I solve it!
– Da_Bushwacker
Nov 14 '18 at 15:20
You shouldn't need () around "onclick" AFAIK. But good luck! Just don't try For Each loop with nodeList or inspecting in locals window - that will crash Excel.
– QHarr
Nov 14 '18 at 15:58
|
show 3 more comments
You have two a
tag elements there with an onclick
You can get both with attribute = value CSS selector using "*"
contains operator to search for a substring in the attribute value
a[onclick*='UpdatePartRow']
You can grab both with querySelectorAll
method of HTMLDocument object
Dim nodeList As Object
Set nodeList = HTMLDoc.querySelectorAll("a[onclick*='UpdatePartRow']")
The two matches, for your sample, are as follows:
index 0
<a onclick="UpdatePartRow(); chkKeepSubmitPR(); return false;" href="">
index 1
<a onclick="var doc = window.document.forms[0]; UpdatePartRow(); chkKeepSubmitPR(); if (doc.OrgMatrixYes.value == "Y") VerifyDeptOrgMatrix(); return false;" href="">
You can access the nodeList by index e.g.
nodeList.item(0).Click
nodeList.item(0).FireEvent "onclick"
You have two a
tag elements there with an onclick
You can get both with attribute = value CSS selector using "*"
contains operator to search for a substring in the attribute value
a[onclick*='UpdatePartRow']
You can grab both with querySelectorAll
method of HTMLDocument object
Dim nodeList As Object
Set nodeList = HTMLDoc.querySelectorAll("a[onclick*='UpdatePartRow']")
The two matches, for your sample, are as follows:
index 0
<a onclick="UpdatePartRow(); chkKeepSubmitPR(); return false;" href="">
index 1
<a onclick="var doc = window.document.forms[0]; UpdatePartRow(); chkKeepSubmitPR(); if (doc.OrgMatrixYes.value == "Y") VerifyDeptOrgMatrix(); return false;" href="">
You can access the nodeList by index e.g.
nodeList.item(0).Click
nodeList.item(0).FireEvent "onclick"
edited Dec 24 '18 at 13:11
answered Nov 13 '18 at 13:12
QHarrQHarr
32.4k82042
32.4k82042
So I modified the VBA code to include: 'Dim nodeList As Object Set nodeList = HTMLDoc.querySelectorAll("a[onclick*='UpdatePartRow']")' and I set the node list: HTMLDoc.all.CommodityMainSub.Value = ThisWorkbook.Sheets("sheet1").Range("B17") Set nodeList = HTMLDoc.querySelectorAll("a[onlick*='UpdatePartRow']") nodeList.Item(0).Click nodeList.Item(0).FireEvent "onclick" It is still not giving me the result I am hoping for of "clicking" on the button. Am I messing something up? thank you for the help so far!
– Da_Bushwacker
Nov 14 '18 at 14:53
Any errors? And did you try replacing the 0 with 1 throughout?
– QHarr
Nov 14 '18 at 15:04
It ran through the code in VBA with no errors popping up in VBA/Excel. I have tried changing the 0 to 1. I have also tried to change it to chkKeepSubmitPR instead of the UpdatePartRow.
– Da_Bushwacker
Nov 14 '18 at 15:18
I think I just found it! But I made the website crash! nodeList.item(0).FireEvent "onclick" needed to be nodeList.item(0).FireEvent ("onclick"). The webpage is now giving me an error saying "Quantity must be greater than zero, unable to complete request!". So now I have to figure out why it is doing that and how I can fix that. That you so much @QHarr. I will let you know if I have more questions or the completed code once I solve it!
– Da_Bushwacker
Nov 14 '18 at 15:20
You shouldn't need () around "onclick" AFAIK. But good luck! Just don't try For Each loop with nodeList or inspecting in locals window - that will crash Excel.
– QHarr
Nov 14 '18 at 15:58
|
show 3 more comments
So I modified the VBA code to include: 'Dim nodeList As Object Set nodeList = HTMLDoc.querySelectorAll("a[onclick*='UpdatePartRow']")' and I set the node list: HTMLDoc.all.CommodityMainSub.Value = ThisWorkbook.Sheets("sheet1").Range("B17") Set nodeList = HTMLDoc.querySelectorAll("a[onlick*='UpdatePartRow']") nodeList.Item(0).Click nodeList.Item(0).FireEvent "onclick" It is still not giving me the result I am hoping for of "clicking" on the button. Am I messing something up? thank you for the help so far!
– Da_Bushwacker
Nov 14 '18 at 14:53
Any errors? And did you try replacing the 0 with 1 throughout?
– QHarr
Nov 14 '18 at 15:04
It ran through the code in VBA with no errors popping up in VBA/Excel. I have tried changing the 0 to 1. I have also tried to change it to chkKeepSubmitPR instead of the UpdatePartRow.
– Da_Bushwacker
Nov 14 '18 at 15:18
I think I just found it! But I made the website crash! nodeList.item(0).FireEvent "onclick" needed to be nodeList.item(0).FireEvent ("onclick"). The webpage is now giving me an error saying "Quantity must be greater than zero, unable to complete request!". So now I have to figure out why it is doing that and how I can fix that. That you so much @QHarr. I will let you know if I have more questions or the completed code once I solve it!
– Da_Bushwacker
Nov 14 '18 at 15:20
You shouldn't need () around "onclick" AFAIK. But good luck! Just don't try For Each loop with nodeList or inspecting in locals window - that will crash Excel.
– QHarr
Nov 14 '18 at 15:58
So I modified the VBA code to include: 'Dim nodeList As Object Set nodeList = HTMLDoc.querySelectorAll("a[onclick*='UpdatePartRow']")' and I set the node list: HTMLDoc.all.CommodityMainSub.Value = ThisWorkbook.Sheets("sheet1").Range("B17") Set nodeList = HTMLDoc.querySelectorAll("a[onlick*='UpdatePartRow']") nodeList.Item(0).Click nodeList.Item(0).FireEvent "onclick" It is still not giving me the result I am hoping for of "clicking" on the button. Am I messing something up? thank you for the help so far!
– Da_Bushwacker
Nov 14 '18 at 14:53
So I modified the VBA code to include: 'Dim nodeList As Object Set nodeList = HTMLDoc.querySelectorAll("a[onclick*='UpdatePartRow']")' and I set the node list: HTMLDoc.all.CommodityMainSub.Value = ThisWorkbook.Sheets("sheet1").Range("B17") Set nodeList = HTMLDoc.querySelectorAll("a[onlick*='UpdatePartRow']") nodeList.Item(0).Click nodeList.Item(0).FireEvent "onclick" It is still not giving me the result I am hoping for of "clicking" on the button. Am I messing something up? thank you for the help so far!
– Da_Bushwacker
Nov 14 '18 at 14:53
Any errors? And did you try replacing the 0 with 1 throughout?
– QHarr
Nov 14 '18 at 15:04
Any errors? And did you try replacing the 0 with 1 throughout?
– QHarr
Nov 14 '18 at 15:04
It ran through the code in VBA with no errors popping up in VBA/Excel. I have tried changing the 0 to 1. I have also tried to change it to chkKeepSubmitPR instead of the UpdatePartRow.
– Da_Bushwacker
Nov 14 '18 at 15:18
It ran through the code in VBA with no errors popping up in VBA/Excel. I have tried changing the 0 to 1. I have also tried to change it to chkKeepSubmitPR instead of the UpdatePartRow.
– Da_Bushwacker
Nov 14 '18 at 15:18
I think I just found it! But I made the website crash! nodeList.item(0).FireEvent "onclick" needed to be nodeList.item(0).FireEvent ("onclick"). The webpage is now giving me an error saying "Quantity must be greater than zero, unable to complete request!". So now I have to figure out why it is doing that and how I can fix that. That you so much @QHarr. I will let you know if I have more questions or the completed code once I solve it!
– Da_Bushwacker
Nov 14 '18 at 15:20
I think I just found it! But I made the website crash! nodeList.item(0).FireEvent "onclick" needed to be nodeList.item(0).FireEvent ("onclick"). The webpage is now giving me an error saying "Quantity must be greater than zero, unable to complete request!". So now I have to figure out why it is doing that and how I can fix that. That you so much @QHarr. I will let you know if I have more questions or the completed code once I solve it!
– Da_Bushwacker
Nov 14 '18 at 15:20
You shouldn't need () around "onclick" AFAIK. But good luck! Just don't try For Each loop with nodeList or inspecting in locals window - that will crash Excel.
– QHarr
Nov 14 '18 at 15:58
You shouldn't need () around "onclick" AFAIK. But good luck! Just don't try For Each loop with nodeList or inspecting in locals window - that will crash Excel.
– QHarr
Nov 14 '18 at 15:58
|
show 3 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53281519%2fselecting-a-html-button-in-excel-vba-that-does-not-have-an-id%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Are you sure it's a button, it has an <a> tag. You could try to get the item, and then invoke its click method using
.fireevent("click")
– Nathan_Sav
Nov 13 '18 at 13:02
Can you provide an URL?
– QHarr
Nov 13 '18 at 13:16
@QHarr, it is a company specific URL that has data on purchasing projects, for several reasons I cannot share it.
– Da_Bushwacker
Nov 14 '18 at 14:32
ok... well give the below a try and let me know :-)
– QHarr
Nov 14 '18 at 14:37