Need HTML help please....

TNTScrub

New Member
Joined
Jan 7, 2021
Messages
14
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I've been beating my head against my keyboard in frustration for at least 4 days trying to solve this. The HTML I'm forced to deal with has duplicate id issues. Can anyone tell me how to create a code that identifies or at least lets me click on the second one? These are the two lines of Code I'm dealing with.

<input name="butDelete" class="btn btn-danger" id="butDelete" type="submit" value="Delete">

<input name="butDelete" class="btn btn-primary" id="butDelete" type="submit" value="Delete This Cycle Record">
 

TNTScrub

New Member
Joined
Jan 7, 2021
Messages
14
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I know its a mess but I havnt really tried to clean it up yet. Effectively everything works until just after the next statement. Then I get nothing not even an error.

VBA Code:
Sub Delete_Cycle()

Dim ie As Object
Set ie = GetIE
On Error Resume Next
ie.Visible = True
Dim Doc As HTMLDocument
Set Doc = ie.document
TagN = ActiveCell.Value               'Tag Number
If Not IsEmpty(TagN) Then
ie.document.all("txtNumber").Value = TagN
ie.document.all("butQuickSearch").Click
End If
Application.Wait (Now + TimeValue("0:00:02"))
Set HTML = ie.document
Set ElementCol = HTML.getElementsByTagName("a")
For Each link In ElementCol
If link.innerHTML = "View/Update" Then
link.Click
End If
Next
ie.document.GetElemntsBytagName("butDelete")(1).Click
end sub
 

Some videos you may like

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

TNTScrub

New Member
Joined
Jan 7, 2021
Messages
14
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Check with Value parameter.

VBA Code:
For Each htmlobject In HTMLDoc.getElementsByTagName("input")
            If htmlobject.value = "Delete This Cycle Record" Then
                htmlobject.Click
            Exit For
        End If
    Next
Again, I don't even get an error.

VBA Code:
Sub Delete_Cycle()

Dim ie As Object
Set ie = GetIE
On Error Resume Next
ie.Visible = True
Dim Doc As HTMLDocument
Set Doc = ie.document
TagN = ActiveCell.Value               'Tag Number
If Not IsEmpty(TagN) Then
ie.document.all("txtNumber").Value = TagN
ie.document.all("butQuickSearch").Click
End If
Application.Wait (Now + TimeValue("0:00:02"))
Set HTML = ie.document
Set ElementCol = HTML.getElementsByTagName("a")
For Each link In ElementCol
If link.innerHTML = "View/Update" Then
link.Click
End If
Next
'ie.document.all("butDelete")(1).Click
Dim htmlobject As Object
Set HTMLDoc = ieBrowser.document
For Each htmlobject In HTMLDoc.getElementsByTagName("input")
If htmlobject.Value = "Delete This Cycle Record" Then
htmlobject.Click
Exit For
End If
    Next
 

Saurabhj

Active Member
Joined
Jun 6, 2020
Messages
413
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi,

Make some changes as below but have a doubt. You click twice (on a button and then on a link)

Is this opening a new page ?

VBA Code:
Sub checkDetails()
    On Error Resume Next
    Dim HTMLDoc As New HTMLDocument
    Dim ieBrowser As New InternetExplorer
    
    Dim rowno As Integer
    Dim htmlobject As Object
    Dim trow As Object
    Dim siteURL As String
    
    siteURL = "https://yoursite/"
   
    'To open and show Internet Explorer
    ieBrowser.Visible = True
    
    'To Open website in Internet Explorer
    ieBrowser.navigate siteURL
    
    Do
    ' Wait till the Browser is loaded
    Loop Until ieBrowser.readyState = READYSTATE_COMPLETE
    
    TagN = ActiveCell.Value               'Tag Number
    
    If Not IsEmpty(TagN) Then
        ieBrowser.document.all("txtNumber").Value = TagN
        ieBrowser.document.all("butQuickSearch").Click
    End If
    Application.Wait (Now + TimeValue("0:00:02"))
    
    Set HTMLDoc = ieBrowser.document
    
    Set ElementCol = HTMLDoc.getElementsByTagName("a")
    For Each link In ElementCol
        If link.innerHTML = "View/Update" Then
            link.Click
        End If
    Next
    Application.Wait (Now + TimeValue("0:00:02"))
    For Each htmlobject In HTMLDoc.getElementsByTagName("input")
            If htmlobject.Value = "Delete This Cycle Record" Then
                htmlobject.Click
            Exit For
    Next
      
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,127,217
Messages
5,623,459
Members
415,971
Latest member
Graeme M

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
Top