Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fill In File Input Field with VBscript

Status
Not open for further replies.

Thenolos

Technical User
Jul 15, 2004
38
Hello,

I'm creating an application that logs on to a website and files paperwork with that website automatically. Everything is going peachy with the exception of uploading my PDF documents to the site (one of the final stages). I know the direct file location to the PDFs and want to have that location placed in the "Choose file:" field on the website.

Unfortunately the File input type does not work the same way as a normal text box... so something like this:

Code:
With obIE.Document.Frames("main").Document
    .all.Item("file_1").Value = "c:\file.pdf"
End With

will not work...

Does anybody have any ideas of how I might do this without using SendKeys?

Thanks for any help.
 
Thanks for your reply, Mark, but It's not quite what I am looking for. I do not control the website that I am uploading to, I am merely creating an application that runs throught the filing process on a website we subscribe to.

Near the end of the filing process, I need to upload a PDF document to the website. My initial thought was to just do something like:

Code:
With obIE.Document.Frames("main").Document
    .all.Item("file_1").Value = "c:\file.pdf"
    .Forms(0).Submit
End With

The idea is to fill in the textbox with the file path and then simulate a click on the submit button. However setting the inputs value to the path name has no effect--the value remains null, though no error is thrown at me.

So I need to find a way to fill in that field without resorting to SendKeys..
 
Are you able to view the form properties?

I hope you find this post helpful.

Regards,

Mark
 
Link

Finally found someone asking the same question on Google... doesn't look good for me. Makes sense thought... Looks like I get to break my rule of no SendKeys. Yay.

Thanks for the help though. :) Sorry to waste your time.
 
File type input value is readonly for security reason.
 
For anyone who may need to do this in the future that searches and finds this thread... the SendKeys workaround is simple... I just have a natural bias against it.

I just stuck this in after the code that navigated me to the proper page. The file field was the first on the page... you may need to send the tab button a few times if the webpage is filled out differently.

Code:
Dim obShell As Object
Set obShell = CreateObject("WScript.Shell")
obShell.SendKeys "c:\hello.txt"
 
Make sure you use app.activate when using sendkeys to ensure your focus is on the desired application.

I hope you find this post helpful.

Regards,

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top