I am currently doing automaiton for file uploading
Below is HTML tag for input file tag:
<input name="file" title="Type the path of the file or click the Browse button to find the file." id="file" type="file" size="20">
And below is button HTML Tag:
<input name="Attach" title="Attach File (New Window)" class="btn" id="Attach" onclick="javascript:setLastMousePosition(event); window.openPopup('/widg/uploadwaiting.jsp', 'uploadWaiting', 400, 130, 'width=400,height=130,resizable=no,toolbar=no,status=no,scrollbars=no,menubar=no,directories=no,location=no,dependant=no', true);" type="submit" value="Attach File">
My VBA coding is:
Dim filee As Object
Set filee = mydoc.getElementById("file")
filee.Value = filenamepath
Set attach = mydoc.getElementsByName("Attach")
attach(0).Click
When I am running this coding, input filepath box not assign path name so i am getting chose file path.
Finally i have tried below code but that send key not executing
Dim filee As Object
Set filee = mydoc.getElementById("file")
filee.Click
obj.SetText filename
obj.PutInClipboard
SendKeys "^v"
SendKeys "{ENTER}"
Set attach = mydoc.getElementsByName("Attach")
attach(0).Click
Set finall = mydoc.getElementsByName("cancel")
finall(0).Click
Kindly tell me the windows API program to assign my file name directory in fine name: input box on opened Choose File to Open explorer and click the open button.
As setting the value of a file input element is disabled due to security reasons, the "send keys" method seems to be the only option for automating file uploads using the IE API.
I just stumbled over the same problem that the code after the
Click
does not seem to be executed - that is, unless the dialog is closed. This indicates that theClick
method is blocking, making it impossible to interact with the dialog from within the macro.I could solve that by using a different method to open the dialog: by setting the focus to the file element with
Focus
, and sending the space key withSendKeys
.In your case, replace
with
I fixed this issue by running external VBScript contain file path to set it on 'Choose File to Upload' pop up window using SendKeys method after send Enter Key to close this pop up, and this run successfully because the extranl VBScript run on another process so it will not stuck on VBA code.
Notes: 1- I dynamically create the external VBScript from VBA code and save it on Temp folder after that I run this script using WScript.Shell.Run to excute it on another thread 1- At the begining of the external VBScript I set 1 sec delay to be sure the 'Choose File to Upload' pop up window already opened from VBA.
And here is the complete code: