Using VBA to enter filename on a Webpage

jace808

New Member
Joined
Jan 14, 2010
Messages
7
I have a simple text box I need to fill in with my email which I have managed to do very simply with this code;
Code:
Dim IE As InternetExplorer
Dim sIEWindowName As String
Set IE = New InternetExplorer
 
IE.Visible = True
 
sIEWindowName = "Some Webpage - Windows Internet Explorer"
 
IE.Navigate "[URL]http://somewebsite.iuse.com[/URL]"
'
Do While IE.Busy: DoEvents: Loop
Do While IE.ReadyState <> 4: DoEvents: Loop
 
IE.Document.form1.Email.Value = "[EMAIL="my.name@someisp.com"]my.name@someisp.com[/EMAIL]"
The layout looks like this with my email.value entered in.



I'm using Access 2007, but that is irrelevant for the VBA.

My problem is I can't enter the filename as easily. I have to use SENDKEYS to TAB over then a bunch of other tacky SENDKEY commands to load my file. Even though it works I don't feel it's reliable and would rather just fill the file name in a bit easier.

I used IE developer to show before and after using the BROWSE button to load the file location as seen in pic 1 and pic 2.





The code below has been my best attempt. It runs without error but it does not give me the result I need which is a file location for the application to pull.

Code:
    IE.Document.form1.FileName.Value = "C:\New Folder\aFileToUpload.txt"
 

Some videos you may like

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,370
Your HTML form has an < input type="file"> tag, but IE ignores the element value as a security precaution.

The < form> tag probably has METHOD=post and ENCTYPE="multipart/form-data" attributes. If so, you could use something like http://www.motobit.com/tips/detpg_uploadvbaie/ to upload a file without user interaction, as well as setting the other form input fields.
 

jace808

New Member
Joined
Jan 14, 2010
Messages
7
I don't quite understand the code used here and if used as is my other controls and textboxes are lost since this sub wants to "navigate" to the url clearing my inputs.
 

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,370
I don't understand your last post.

As I said, IE ignores any value you set for < input type="file" >, whether set by VBA (e.g. your IE.Document.form1.FileName.Value = "C:\New Folder\aFileToUpload.txt"), Javascript, or VBScript etc. The only ways I know to upload a file via a web page are by clicking the Browse button and selecting the file (by normal manual user interaction or SendKeys) or by using the form upload method in the link I posted. You are right about SendKeys: it isn't reliable and generally not recommended, so you are lucky that it has worked for you.

Can't really help you further without knowing the URL or at least the HTML code between the < form> and < /form> tags to see whether the motobit technique is applicable.
 

jace808

New Member
Joined
Jan 14, 2010
Messages
7
Your link did lead me to something MUCH easier and faster and works by automation and no SENDKEYS.

Twebst

The lite version of this app will record like a macro and spit out code to use. The only code it will create in the lite version is VBScript which I've pasted in to my project and does the trick quite nicely. Matter of fact I will probably get my boss to purchase the pro version (a little pricey) as well because it is just too good to be true.

In a round about way you did help me so thanks. :)
 

agentsmith128

New Member
Joined
Feb 27, 2014
Messages
1
Twebst has become open source and you can get it for free at: https://github.com/codecentrix/open-twebst/releases

Your link did lead me to something MUCH easier and faster and works by automation and no SENDKEYS.

Twebst

The lite version of this app will record like a macro and spit out code to use. The only code it will create in the lite version is VBScript which I've pasted in to my project and does the trick quite nicely. Matter of fact I will probably get my boss to purchase the pro version (a little pricey) as well because it is just too good to be true.

In a round about way you did help me so thanks. :)
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,106,561
Messages
5,512,070
Members
408,878
Latest member
stams

This Week's Hot Topics

  • Sort code advice please
    Hi, I have the code below which im trying to edit but getting a little stuck. This was the original code which worked fine,columns A-F would sort...
  • SUMPRODUCT with nested If statement
    Hi everyone, Hope you're all well. I'm hoping someone will be able to point me in the right direction with a problem I'm having with a SUMPRODUCT...
  • VBA - simple sort is killing me!
    Hello all! This should be so easy, but not for me, apparently! I have a table of data that can be of varying lengths and widths. My current macro...
  • Compare Two Lists
    I have two Lists and I need to be able to Identify differences between them. List 100 comes from a workbook - the other is downloaded form the...
  • Formula that deducts points for each code I input.
    I am trying to create a formula that will have each student in my class start at 100 points and then for each code that I enter (PP for Poor...
  • Conditional formatting formula required for day of week and a value
    Hi, I have a really simple spreadsheet where column A is the date, column B is the activity total shown as a number and column C states the day of...
Top