VBA IE Automation - upload a file

I am using VBA to automate IE to upload a file to a site. I have got to the point where I have found the button with the "file" type, but then seem to draw a blank when setting the path.

My current VBA looks like this:

Dim btnInput As Object ' MSHTML.HTMLInputElement
Dim ElementCol As Object ' MSHTML.IHTMLElementCollection
.
.
.
Set ElementCol = appIE.Document.getElementsByTagName("input")
     For Each btnInput In ElementCol
        If btnInput.Type = "file" Then
            btnInput.Value = "C:\temp\text.csv"
            Exit For
        End If
    Next btnInput

and the HTML it is reading is this:

<div id="upload-assignments-modal" class="modal hide fade in" tabindex="-1" role="dialog" aria-hidden="false" style="display: block;">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
        <h3 id="myModalLabel">Upload order changes</h3>
    </div>
    <form id="upload-form" enctype="multipart/form-data" action="" method="post" accept-charset="utf-8">
        <div class="modal-body">
            <div style="display:none"><input type="hidden" name="csrfmiddlewaretoken" value="abcde"></div>


                <input type="hidden" name="partner" value="488" id="id_partner">

            <p><label for="id_feed_file">Feed file</label><input type="file" name="feed_file" id="id_feed_file"></p>
            <input type="hidden" name="feed_type" value="390" id="id_feed_type">
        </div>
        <div class="modal-footer">
            <button class="btn" data-dismiss="modal">Cancel</button>
            <button name="action" value="upload" type="submit" class="btn btn-primary">Upload</button>
        </div>
    </form>
</div>

It finds the Type when stepping through and does go to set the value, but then there is no change on screen (I have the IE instance shown as visible for testing) and the file is not added. Would I be right to assume that the "file" input type requires something other than .Value for it's input?

Answers


Give it a try

Set ElementCol = appIE.Document.getElementsByTagName("input")
     For Each btnInput In ElementCol
        If btnInput.Type = "file" Then
            btnInput.Value = "C:\temp\text.csv"
            btnInput.FireEvent ("onclick")
            Exit For
        End If
    Next btnInput

Need Your Help

Chrome plugin process - npapi plugin

plugins google-chrome npapi

I'm writing an npapi plugin in Qt. My plugin works perfectly on firefox and opera. The problem in chrome i guess is regarding the "process-per-plugin" setup. What happens is, when i first open a pa...