Skip to content Skip to sidebar Skip to footer

Manipulate Ie With Vba And A Modal Form

I'm trying to automate the uploading of an excel document to a particular webpage. I can't link it as it requires an account. There is a form with a an browse section (of type=fil

Solution 1:

So after much digging I decided that I had to just have VBA run an external script that checks for the window and input the file name then presses enter. Currently the issue is that it focuses on the file window so if you aren't in the right folder it doesn't work, but if you are it will select the right file and click open!

The vba:

Dim retval As Variantretval= Shell("PowerShell .'" & path & "upload_tester.ps1 file_name'", 1)

where the path is where it is stored, upload_tester.ps1 is the script name and file_name is to pass to the script to input to file browser.

The script:

param(
[Parameter(Mandatory=$true)][string]$a
)

$wshell = new-object -com wscript.shell

while(! $wshell.appactivate("Choose File to Upload")){
start-sleep -milliseconds 100
}

$wshell.appactivate("Choose File to Upload")
start-sleep -milliseconds 500;
$wshell.sendkeys($a)
$wshell.sendkeys("{ENTER}")

This will check until the file explorer window is open, type in the file name to match it, and then press enter to select it. If anyone knows how to get it to focus on the text box part rather than the file explorer part that would be great but otherwise this works for my purpose!

Post a Comment for "Manipulate Ie With Vba And A Modal Form"