Please advise the codes I used

LadyTiara

New Member
Joined
Feb 20, 2018
Messages
11
Hi

I got the below vba code from this site. The code will automatically open the site in IE(will be using different url) and will import files as well. When I ran this code,it did not work due to incorrect elementsTagName and maybe InputType as well. What should be the correct codes? I am not sure. The second part is the html codes.

Please help check the codes.

Code:
Sub File_Test() 
Dim HTMLDoc As MSHTML.HTMLDocument 
Dim HTMLButtons As MSHTML.IHTMLElementCollection Dim HTMLButton As MSHTML.IHTMLElement 
Dim btnInput As MSHTML.IHTMLInputElement 
Dim ie As Object 
Dim pointer As Integer 
Set ie = CreateObject("internetexplorer.application") ie.Visible = True ie.navigate "http://www.htmlquick.com/reference/tags/input-file.html" 

Do While ie.readyState <> READYSTATE_COMPLETE Loop 

Set HTMLDoc = ie.document 
Set HTMLButtons = HTMLDoc.getElementsByTagName("Upload Files") 
For Each HTMLButton In HTMLButtons 

For Each btnInput In HTMLButtons 

If btnInput.Type = "button" Then HTMLButton.Click btnInput.Value = "C:\temp\test.txt" pointer = 1 Exit For 

End If 
Next btnInput If pointer = 1 Then Exit For Next

End sub
]


HTML:
    <button title="Upload Files" class="button button--white xc-action-nav__button ng-binding ng-scope" type="button" loading-key="0" ng-click="setLoading('group1', '0'); " ng-disabled="isLoading('group1', null)"><span class="spinner-transition" ng-class="{'spinner spinner--is-loading': isLoading('group1', '0')}"></span> Upload Files</button>
Thank you!
 

DanteAmor

Well-known Member
Joined
Dec 3, 2018
Messages
8,790
Office Version
2007
Platform
Windows
I did tests with the following and it doesn't send me an error, it reaches the part where it opens a window to select a file.

Code:
Sub File_Test()
  Dim HTMLDoc As MSHTML.HTMLDocument
  Dim HTMLButtons As MSHTML.IHTMLElementCollection
  Dim HTMLButton As MSHTML.IHTMLElement
  Dim btnInput As MSHTML.IHTMLInputElement
  Dim ie As Object
  Dim pointer As Integer
  '
  Set ie = CreateObject("internetexplorer.application")
  ie.Visible = True
  ie.navigate "http://www.htmlquick.com/reference/tags/input-file.html"
  Do While ie.readyState <> READYSTATE_COMPLETE
  Loop
  Set HTMLDoc = ie.document
  Set HTMLButtons = HTMLDoc.getElementsByName("[COLOR=#0000ff]uploadedfile[/COLOR]")
  For Each HTMLButton In HTMLButtons
    For Each btnInput In HTMLButtons
      If btnInput.Type = "[COLOR=#0000ff]file[/COLOR]" Then
        HTMLButton.Click
        btnInput.Value = "C:\temp\test.txt"
        pointer = 1
        Exit For      
      End If
    Next btnInput
    If pointer = 1 Then Exit For
  Next
End Sub
 
Last edited:

Forum statistics

Threads
1,081,863
Messages
5,361,743
Members
400,654
Latest member
Pinaki Chatterjee

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top