In this tutorial we would learn: 1. How to automate File uploads using excel macro. 2. Calling vb script from excel macro For pre-requisites to this tutorial please refer below tutorial: • How to Automate Web Sc...
Very underrated video. I have been trying to find this solution for far too long. Thank you! I am able to modify the code for my use and it works perfectly!
Hello Sir, For the past 7 days, I was going crazy to find a way to automate the file upload process. I was stuck passing the file name in the file input box. Your tutorial is clean and helped me a lot. Thanks a lot.
Thanks a tonne my friend ! Wonder why google doesnt throw up your video first when you search for how to upload a file in a VBA script - especially - when doing WebForms. Brilliant video Sir !
Very Helpful!! I find my cursor is not always in the same place in the select file window (probably a new feature since video posted). A suggestion is to replace the "{tab}" section of the shell script with: WshShell.SendKeys "%{n}" WScript.Sleep 2000 WshShell.SendKeys "^{v}" WScript.Sleep 2000 WshShell.SendKeys "%{o}" This is alt-n, ctrl-v, alt-o -- alt-n takes you directly to the filename input field, ctrl-v pastes, alt-o activates the 'Open' btn.
Amazing, neat and clear explanation even I am new to excel macro able to understand the concept clearly. Started with edge browser and performed few operation(sendkeys, click, drop downs, check box) r but i am unable to automate file upload. Kindly provide steps to automate File Uploads in edge browser which helps me a lot. Thanks in advance.
Code written in vbs file must be written in the vba macro itself for edge. No need to use separate vbs file for file uploads on edge and chrome browsers.
Hi, thanks for this wonderful video - really cool, just if u could also help with the loop - actually i want to upload 50files so looking for loop code to copy the path from excel file and do the upload and come back again to copy next one till last, any help will be appreciated
Hi thanks for the codes, seems good. I’m trying the same example file of yours but once the upload window opens “windows script host settings” nothing happens later. Then excel is waiting for “ to complete an ole action
Hello sir, nice video... I have tried to upload images in my wordress website but I am getting run time error. can you please make a video how can upload image in WordPress with macro ? thank you
Thank you so much, this was very helpful! But I have run into an issue. When I run this, sometimes the script pastes the correct file path into the file name box, but sometimes the script just types in "v" into the file name box, so it seems the script is missing the ^ (Ctrl) sometimes when it runs. Do you know why this would happen?
Hi, I can go into the website using macro but I keep getting prompt with there is no script engine for the extension ".xlsm". The file I want to upload is an Excel File btw. Do you know what's causing this?
can we do the same from google chrome rather than IE ? , if so please help us by providing the code for the same.. because most of the company which we are working has started using chrome than IE , may be for the speedness .. so request you to make a saparate video or you can do the continuation of this same with chrome.. pls ..
Refer below tutorial for web automation using chrome: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE--GUw22ecRwI.html For file upload automation use the same techhique as explained or copy the vbs script code in moacro module. It will work
how do we automate in case if there are 100s of files created everyday? and we have submit 1 file only once and we have to keep on uploading newer files to the upload link. i am asking this for a manufacturing company quality lab. Thanks
For chrome or edge refer below tutorial: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-AEp0Yeis9AM.html Apply the sam logic for file upload. The script is provided in the blog itself.
When my upload file path contain space in it then I am facing issue in pasting the path. Can you please help. Eg path : E://New Folder/file.txt In this above scenario while pasting the url only "E://New" is getting pasted
Hello, Once I run the VBA everything works fine, but after the VBS script sends the sendkey {enter}, my file does upload but I get a "windows script host error" saying "There is no file extension in "c:\Users\alain\onedrive\desktop\automation\loan" but my full path in VBA is "C:\Users\alain\OneDrive\Desktop\Automation\Loan Entry\Resources\FileUpload.VBS". It seems to cut off the last part of it and I don't know why? any suggestions?
if you see there is space between Loan and Entry in the 'Loan Entry' folder. This technique fails if there are spaces in the file path. Try to rename the folders without space and try
@@AutomationMadeEasy Thank you So much for the help! that fixed that issue!!! I have one final question. I am have a macro that calls this macro and sometimes instead of pasting the file path into the upload window, it just pastes as "v" as if it didn't pick up the "^" for the command +v paste sendkey. any recommendation? Overall this has been super helpful
this approach needs the window to stay in focus so it wont work if remote desktop is minimized. But on certain web pages it is possible to enter file path without opening the File upload dialog. Will need to to see your web page to assess if that approach can be used
Thanks, I after researching I did it with this FindElementByXPath(".../div[1]/span/input").SendKeys (dirFile) , which seems to be another way to do it without needing vbs
I need to upload all the files in a folder. I can use wshshell.sendkeys "^{A}" to select all the files, but then, how to modify this line Shell "wscript.exe " & strFile & " " & strUploadFile Really don't want want to have to resort to uploading all the files individually. Any help greatly appreciated.
The execution is stopping at the below line Shell "wscript.exe " & strVBSFile & " " & strUploadFile saying " Run Time Error 5 - Invalid procedure call " Not even opening the choose file to upload window as the command to click on browse is below this line. please explain how is it working for you
Dim IE As Object Dim strVBSFile As String Dim strUploadFile As String Set IE = CreateObject("InternetExplorer.Application") IE.Navigate "www.automationandagile.com/p/sample-form.html" IE.Visible = True Do While IE.Busy Or IE.ReadyState 4 Application.Wait DateAdd("s", 1, Now) Loop strVBSFile = "E:\VBA\FileUpload.vbs" strUploadFile = "E:\VBA\Book1.xlsm" Shell "wscript.exe " & strVBSFile & " " & strUploadFile IE.Document.getElementsByName("myFile")(0).Click Application.Wait DateAdd("s", 2, Now) End Sub
@@AutomationMadeEasy hello thanks for looking into the code pls look into the vba 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
I am getting the error 462 which says The remote server machine does not exist or is unavailable. Ay idea how to resolve this? I checked and followed everything and also took note of comments added everything.
@@AutomationMadeEasy Thanks for getting back. Really appreciate it. The page opens but then the upload is not working there is when i get the error. The below is the code i copied from your provided space. But in turn i am trying to upload a folder from desktop to Dropbox and then use those uploaded image files back into excel and then then convert them into URL's. The below is the vbs file: Set WshShell = CreateObject("WScript.Shell") Do ret = WshShell.AppActivate("Choose File to Upload") Loop Until ret = True WScript.Sleep 1000 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 1000 Set WshShell = nothing The next is the module code: Sub uploadFiles() Set IE = CreateObject("InternetExplorer.Application") IE.navigate "www.automationandagile.com/p/sample-form.html" IE.Visible = True Application.Wait DateAdd("s", 5, Now) strFile = "C:\Users\user\Desktop\UploadFile.vbs" '--Mention path where you stored the .vbs file in Step 3 strUploadFile = "C:\Users\user\Desktop\EUebGt1XkAYe9N81.png" '--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
@@AutomationMadeEasy here is my code Sub testauto() Dim obj As New WebDriver obj.Start "edge", "" obj.Get "My Website Admin URL" obj.FindElementByName("log").SendKeys ("Website USERNAME") obj.FindElementByName("pwd").SendKeys ("Website Password") obj.FindElementByName("wp-submit").Click obj.Get "Website Post URL Where I want to Upload Image" strUploadFile = "E:\AbcMall.png" strVBSFile = "E:\UploadFile.vbs" Shell "wscript.exe " & strVBSFile & " " & strUploadFile obj.FindElementByXPath("//*[@class='wpsm_tax_helper_upload_image_button button']").Click obj.FindElementById("menu-item-upload").Click obj.FindElementById("__wp-uploader-id-1").Click Application.Wait DateAdd("s", 2, Now) obj.FindElementById("attachment-details-alt-text").SendKeys ("sumit") obj.FindElementByXPath("//*[@class='button media-button button-primary button-large media-button-select']").Click Application.Wait DateAdd("s", 2, Now) End Sub _______________________________________________ VBS FILE CODE _______________________________________________ Set WshShell = CreateObject("WScript.Shell") Do ret = WshShell.AppActivate("Open") Loop Until ret = True WScript.Sleep 1000 ret = WshShell.AppActivate("Open") If ret = True Then WshShell.Run "cmd.exe /c echo " & WScript.Arguments(0) &"|clip", 0, True WScript.Sleep 5000 WshShell.SendKeys "{TAB}" WScript.Sleep 2000 WshShell.SendKeys "{TAB}" WScript.Sleep 4000 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 1000 Set WshShell = nothing The Image path is copied but It was unable to paste in the dialogbox. I am using wordpress website, Windows 10 and Microsoft Office 2019 Version and I am using selenium basic for automation. Can you please check and tell me is there any problem ? Thank you so much.
Since you are using selenium vba, No need to use seperate vbs file. After clicking on browse button you can use the tab and enter keys as given below: Set WshShell = CreateObject("WScript.Shell") WshShell.Run "cmd.exe /c echo " & strUploadFile &"|clip", 0, True Application.Wait DateAdd("s", 2, Now) obj.FindElementByXPath("//*[@class='wpsm_tax_helper_upload_image_button button']").Click Application.Wait DateAdd("s", 2, Now) Application.SendKeys "{TAB}" Application.Wait DateAdd("s", 2, Now) Application.SendKeys "{TAB}" Application.Wait DateAdd("s", 2, Now) Application.SendKeys "^{v}" Application.Wait DateAdd("s", 2, Now) Application.SendKeys "{TAB}" Application.Wait DateAdd("s", 2, Now) Application.SendKeys "{TAB}" Application.Wait DateAdd("s", 2, Now) WshShell.SendKeys "{ENTER}"
@@AutomationMadeEasy this is the code in VBA strFile = "E:\2020\Fileupload.vbs" '--Mention path where you stored the .vbs file in Step 3 strUploadFile = "E:\2020\104.pdf" '--Mention path of the file which you wish to upload Shell "Wscript.exe " & strFile & " " & strUploadFile HTMLdoc.all.RawasLhpForm_fbalk.Click and the code below (VBS) : 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 WScript.Sleep 2000 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
Hola Bro, cuando ejecuto la macro y luego de bastantes segundos, me dice : "Microsoft está esperando a que ' ' complete una acción OLE". Que puede ser esto y como lo soluciono? por favor ayuda
@@AutomationMadeEasy Hola por supuesto. Aquí lo detallo. Los dos archivos están guardados en C:\CARPTEMPORAL. Por favor ayuda 'Este es el Codigo VBA Sub uploadFile() Set IE = CreateObject("InternetExplorer.application") IE.navigate "girardot-cundinamarca.gov.co/Ciudadanos/Paginas/Carga-Archivo.aspx" IE.Visible = True Do While IE.Busy Or IE.readyState 4 Application.Wait DateAdd("s", 1, Now) Loop strUploadFile = "C:\CARPTEMPORAL\text1.txt" strVBSFile = "C:\CARPTEMPORAL\FileUpload.vbs" Shell "WScript.exe " & strVBSFile & " " & strUploadFile IE.document.getElementById("ctl00_ctl58_g_280f7905_95ae_4ab5_b3cd_e1765b71e240_ctl00_ATXT").Click Application.Wait DateAdd("s", 1, Now) End Sub 'ESTE ES EL CÓDIGO DEL SCRIPT Set WshShell = CreateObject("WScript.Shell") Do ret = WshShell.AppActivate("Choose File to Upload") Loop Until ret = True WScript.Sleep 1000 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 1000 Set WshShell = nothing
WshShell.Run "cmd.exe/c echo " & WScript.Arguments(0) &"| clip", 0, True In above command a space is missed after cmd.exe. Correct command is given below: WshShell.Run "cmd.exe /c echo " & WScript.Arguments(0) &"| clip", 0, True
@@AutomationMadeEasy I did it but the problem persists. In Excel say: "Microsft excel está esperando que otra aplicación complete una acción OLE" Please help me, how can i solve it?
@@AutomationMadeEasy Thank you so much for guidance and such code. Now it is working well. I was searching on internet for many months about uploading a file on html page, but yet not found such code. It is a greate help.
A month ago it worked well. Now on same system the same code is not pasting the image path in file upload window. Recommended shell controls are also checked. Don't know whats wrong happened to it.
@@AutomationMadeEasy Thanks for great video. I got another problem, when using vba to click a option button (totally 2 options) (not the default one), i got error "91". Grateful if could advise. Thanks again.