PDA

View Full Version : IE automation - tricky - how to give the script a file path then click OK ?



Ken Crawford
09-18-2014, 04:22 PM
Hi all,

Long time since I was here last time.

I want to write a macro which would do the following


Go to tinyeye(dot)com website and click Browse to select local fixed image from disk (file path e.g C:\image.jpg)
Macro would then click OK after file path is chosen


So far I came up to below code:



Sub Button1_Click()
Dim ie As Object

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True

ie.navigate "tinyeye(dot)com"
Do While ie.Busy
Application.Wait DateAdd("s", 1, Now)
Loop


Set objCollection = ie.Document.getElementsByTagName("input")
i = 0
While i < objCollection.Length
If objCollection(i).ID = "upload_box" Then
objCollection(i).Click
End If
i = i + 1
Wend


End Sub




I am out of ideas now how to make VBA to pick C:\image.jpg file so then it can click OK. Can any good soul help here? :bug:

westconn1
09-19-2014, 03:11 PM
as the html file inputs can not be automated, it is a difficult task

i wrote a sample using winhttp integrated to get the required values from the webpage
see www.vbforums.com/showthread.php?737921-winhttp-file-upload-using-data-from-html-file-upload-form&p=4526665#post4526665
it may require some modification depending on the requirements of the site

using this type of code may be against some sites terms and conditions