Automate File Uploads
How to automate File Uploads using excel macros?
Steps:
Steps 1: Open notepad
Step 2: Copy below code in the notepad file
Set WshShell = CreateObject("WScript.Shell")
Do
ret = WshShell.AppActivate("Choose File to Upload")
Loop Until ret = True
WScript.Sleep 500
ret = WshShell.AppActivate("Choose File to Upload")
If ret = True Then
WshShell.Run "cmd.exe /c echo " & WScript.Arguments(0) & "| clip", 0, True
WScript.Sleep 2000
WshShell.SendKeys "{TAB}"
WScript.Sleep 2000
WshShell.SendKeys "{TAB}"
WScript.Sleep 2000
WshShell.SendKeys "^{v}"
WScript.Sleep 2000
WshShell.SendKeys "{TAB}"
WScript.Sleep 2000
WshShell.SendKeys "{TAB}"
WScript.Sleep 2000
WshShell.SendKeys "{ENTER}"
End If
WScript.Sleep 500
Set WshShell = nothing
Step 3: Save the file (extension of the file must be ".vbs". Also note the location where you have saved the file.)
Step 4: Open VBA editor on a new excel file and create a new module.
Step 5: Copy below code in the vba module.
Sub uploadFiles()
Set IE = CreateObject("InternetExplorer.Application")
IE.navigate "https://www.automationandagile.com/p/sample-form.html"
IE.Visible = True
Application.Wait DateAdd("s", 5, Now)
strFile = "F:\Excel_Automation\Files\FileUpload.vbs" '--Mention path where you stored the .vbs file in Step 3
strUploadFile = "F:\Files\doc1.jpg" '--Mention path of the file which you wish to upload
Shell "wscript.exe " & strFile & " " & strUploadFile
IE.document.getElementsByName("myFile")(0).Click
Application.Wait DateAdd("s", 2, Now)
End Sub
Step 6: Run the module and enjoy :)