Button Click in Internet - Button without 'Name'!!

23izkool

New Member
Joined
Mar 4, 2011
Messages
19
Hi all,
I am having problem clicking a button in an Internet Browser where the source code for the button only gives the (1) input type & (2) id BUT not the (3) name!
SOURCE CODE FOR BUTTON WITHOUT NAME
<input type="button" id="ImportingButton" class="C00_Button1" value="Importingvalue" *******="performUpload();"/>

I have already successfully written a code to click internet buttons WITH names:
SOURCE CODE FOR BUTTON WITH NAME
<input type="button" name="ImportingButton" id="ImportingButton" class="C00_Button1" value="Importingvalue" *******="performUpload();"/>
VBA CODE TO CLICK BUTTON
Sub ClickButton()
Dim objIE as InternetExplorer, appIE as InternetExplorer
Dim btnInput as MSHTML.HTMLInputElement
Dim ElementCol As MSHTML.IHTMLElementCollection
Dim Done as Long, Nm as Long
Dim url as string
Application.ScreenUpdating = False
Nm = 1234
Set appIE = New InternetExplorer
url = (the website link I'm trying to access)
' ---- click the editbutton (start) ----
Set ElementCol = appIE.document.getElementsByTagName("Input")
For Each btInput In ElementCol
If btInput.name = "ImportingButton" Then
Done = Done + 1
btnInput.Click
End If
Next btnInput
' --- click the editbutton (end) ---
End Sub

** MODIFIED VBA CODE TO CLICK BUTTON **
Sub ClickButton()
Dim objIE as InternetExplorer, appIE as InternetExplorer
Dim btnInput as MSHTML.HTMLInputElement
Dim ElementCol As MSHTML.IHTMLElementCollection
Dim Done as Long, Nm as Long
Dim url as string
Application.ScreenUpdating = False
Nm = 1234
Set appIE = New InternetExplorer
url = (the website link I'm trying to access)
' ---- click the editbutton (start) ----
Set ElementCol = appIE.document.getElementsByTagName("Input")
For Each btInput In ElementCol
If btInput.ID = "ImportingButton" Then
Done = Done + 1
btnInput.Click
End If
Next btnInput
' --- click the editbutton (end) ---
End Sub
When I ran the above macro, the program hung & I had to force-stop the macro by pressing 'Ctrl-Break'
When I investigated the debugging portion --> it highlighted the code 'btnInput.ID...'
Believe this can be solved BUT no clue now..Hope someone can advise!!
Thanks everyone!!!
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hello 23izkool,

If you know the ID, you don't need the name. You can access the object like this in VBA...
Code:
    Set btnInput = appIE.Document.getElementById("ImportingButton")
You must be sure the ID is correct or the object will be set to Nothing. To verify the ID, check the page source of the web page.

Sincerely,
Leith Ross
 
Upvote 0
(Pls ignore previous thread!!) Button Click in Internet - Button without 'Name'!!

Hi all,
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>I am having problem clicking a button in an Internet Browser where the source code for the button only gives the (1) input type & (2) id BUT not the (3) name!
<o:p> </o:p>
SOURCE CODE FOR BUTTON WITHOUT NAME
Rich (BB code):
<input type="button" id="ImportingButton" class="C00_Button1" value="Importingvalue" *******="performUpload();"/>
<o:p> </o:p><o:p> </o:p>
I have already successfully written a code to click internet buttons WITH names:
<o:p> </o:p>
SOURCE CODE FOR BUTTON WITH NAME
Rich (BB code):
<input type="button" name="ImportingButton" id="ImportingButton" class="C00_Button1" value="Importingvalue" *******="performUpload();"/>
<o:p> </o:p>
VBA CODE TO CLICK BUTTON
Sub ClickButton()
<o:p> </o:p>
Dim objIE as InternetExplorer, appIE as InternetExplorer
Dim btnInput as MSHTML.HTMLInputElement
Dim ElementCol As MSHTML.IHTMLElementCollection
Dim Done as Long, Nm as Long
Dim url as string
<o:p> </o:p>
Application.ScreenUpdating = False
Nm = 1234
<o:p> </o:p>
Set appIE = New InternetExplorer
<o:p> </o:p>
url = (the website link I'm trying to access)
<o:p> </o:p>
' ---- click the editbutton (start) ----
<o:p> </o:p>
Set ElementCol = appIE.document.getElementsByTagName("Input")
For Each btInput In ElementCol
If btInput.name = "ImportingButton" Then
Done = Done + 1
btnInput.Click
End If
Next btnInput
<o:p> </o:p>
' --- click the editbutton (end) ---
<o:p> </o:p>
End Sub
<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>
** MODIFIED VBA CODE TO CLICK BUTTON **
Sub ClickButton()
<o:p> </o:p>
Dim objIE as InternetExplorer, appIE as InternetExplorer
Dim btnInput as MSHTML.HTMLInputElement
Dim ElementCol As MSHTML.IHTMLElementCollection
Dim Done as Long, Nm as Long
Dim url as string
<o:p> </o:p>
Application.ScreenUpdating = False
Nm = 1234
<o:p> </o:p>
Set appIE = New InternetExplorer
<o:p> </o:p>
url = (the website link I'm trying to access)
<o:p> </o:p>
' ---- click the editbutton (start) ----
<o:p> </o:p>
Set ElementCol = appIE.document.getElementsByTagName("Input")
For Each btInput In ElementCol
If btInput.ID = "ImportingButton" Then
Done = Done + 1
btnInput.Click
End If
Next btnInput
<o:p> </o:p>
' --- click the editbutton (end) ---
<o:p> </o:p>
End Sub
<o:p> </o:p>
When I ran the above macro, the program hung & I had to force-stop the macro by pressing 'Ctrl-Break'
When I investigated the debugging portion --> it highlighted the code 'btnInput.ID...'
<o:p> </o:p>
Believe this can be solved BUT no clue now..Hope someone can advise!!
Thanks everyone!!
 
Upvote 0
Hello 23izkool,

Can you post either the URL or the page source for the website? I would need one or the other to get the ID for this button, if it does in fact have ID. This property is not mandatory in HTML.

Sincerely,
Leith Ross
 
Upvote 0
Pls ignore previous 2 threads - sorry!

Hi all,

Sorry realized the source code did not show up properly in the previous 2 threads. I already tried "
Code:
------
" but still cannot get it to work.

  • Hope someone can advise on my problem so that I can make progress!
  • Appreciate if the administrator or anyone here can advise me how to post the source codes properly here
Thanks!
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,357
Members
452,907
Latest member
Roland Deschain

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