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!
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
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:
Upvote 0

Forum statistics

Threads
1,214,635
Messages
6,120,660
Members
448,975
Latest member
sweeberry

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