I have a company intranet site that opens a file dialog box (when a input box is clicked) to allow the user to select a file to upload to our main system. Clicking "OK" after selecting a file closes the filedialog box and puts the files location into the input box. I've searched the thread 35411826, which looks like a good answer for some applications - but it does not solve my distinct problem. Our system does more than simply accept an uploaded file. It generates codes for the uploaded file and enters it into several subsystems.
I'd like to automate this by controlling the already opened file dialog box. I've attempted to fill the input box with the location of the file but it does not work. The input box must be clicked on to open the file dialog box, which I can do with the .click command.
Here is the html for the element:
<input id="fileToUploadNewDoc" type="file" size="50">
I imagine the type "file" initiates the element to open a file dialogue box when clicked. I don't know. But that's what happens when the input box is clicked.
How can I locate the open filedialog box and set it to an object variable that would allow me to select a file and click the "OK" button to fill the element with the file location?
Update 01-24-2019: I was asked to provide more coding/explanation.
Briefly:
I have a popup webpage set to the variable IE2. There is an HTML input box on this page with ID of "fileToUploadNewDoc" Here is the HTML code of the document:
<div class="span12">
<div class="control-group">
<label class="control-label" for="selectDocumentType">File to Upload</label>
<input id="fileToUploadNewDoc" type="file" size="50">
</div>
</div>
Here is an image of the input box:
You can see that a "Browse" button has been added to the input box. This is not an actual button, but is placed there by javascript, css, or something. Clicking anywhere in the input box causes a filedialog browsing box to open.
As I said earlier, I attempted to bypass the "Browse" box by filling the input box directly with the location of the file, as shown below:
IE2.document.getElementById("fileToUploadNewDoc").Value = "C:\Users\nunYa\Documents\My Scans\Current Scans\PSA_ABC-54596900.pdf"
But it does not put the location into the input box. In fact nothing happens.
I have also tried:
IE2.document.parentWindow.execScript "$('#fileToUploadNewDoc').val('C:\Users\nunYa\Documents\My Scans\Current Scans\PSA_ABC-54596900.pdf').trigger('change')"
But to no avail. This does not work to put the document location into the input box either.
The only way to interact with this input box (so far as I know) is to click on it, which causes a filedialog box to open for the user to select a folder and file's location to put into the input box when the "OK" button on the filedialog box is clicked. In my simple mind I think that I must assign the open filedialog box to an object variable to programmatically choose a file and click "OK" on the filedialog box.
Generally when a programmer opens a filedialog box he can assign it to an object variable. (There are a thousand examples of that on the internet.) That gives the programmer the ability to control the filedialog box. ie, Select folders and files and to close the filedialog box.
In this case, the website opens the filedialog box, not me the programmer, so I don't have it set to an object variable and therefore can not control it. I need to be able to find the filedialog box and set it to an object variable in order to control it. I don't know how to explain that more simply. I'm sorry if it's confusing.
I also did check out thread 35411826 on controlling dialog boxes. But that thread's answer is not to control the dialog box but rather it explains how to upload a file directly to some website's folder innocuously. As I also explained earlier our work system is not innocuous. When this file is uploaded the server side updates dozens of other systems and creates codes and keys across an entire array of different systems. Uploading the file to some folder on the server would do absolutely nothing.
Boiling it down, this is as simple as I can make the question: How do I find an already open filedialog box and set it to an object variable in VBA so that I can programmatically select a folder and file and then click "OK." I kind of feel like the title of my question explained that but understand why it might be confusing. As this minutia explanation certainly reveals.