Mr.New
Mr.New

Reputation: 27

How To Automate Upload File "Choose File To Upload" in vba Excel

I have an issue to Automate Upload File In Internet Explorer. I have File in VB too , it named Upload.vbs.

The Error Pict :
enter image description here

The codes to click Browse button:

        Set fileS = HTMLdoc.getElementsByTagName("input")

        For Each file In fileS
        file.getAttribute("name") = "Awpform" Then
            file.Click
         End If
        Next file


       Application.Wait DateAdd("s", 4, Now)

enter image description here

       strFileVB = "E:\Upload\Upload.vbs" 


       strUploadFile = "E:\Data\2021\test.xlsx"  

       Shell "Wscript.exe " & strFileVB & " " & strUploadFile 'Here I tried to Run VB

       Application.Wait DateAdd("s", 1, Now)

And Below is the code in Upload.vbs :

Set WshShell = CreateObject("WScript.Shell")
Do
ret = WshShell.AppActivate("Choose File to Upload")
If ret = True Then
   WScript.Sleep 700

dim wsh
Set Wsh = CreateObject("WScript.Shell")

Wsh.Run "cmd.exe /c echo " & WScript.Arguments(0) & "| clip", 0, True 'think I have Error at this line
WScript.Sleep 500
Wsh.SendKeys "{TAB}"

Wsh.SendKeys "{TAB}"

Wsh.SendKeys "^{v}"

Wsh.SendKeys "{TAB}"

Wsh.SendKeys "{TAB}"

WScript.Sleep 700

 Wsh.SendKeys "{ENTER}"
 End If

Loop Until ret = True
set Wsh = nothing

Any help would be greatly appreciated. Thank you

Upvotes: 2

Views: 1301

Answers (1)

Moir
Moir

Reputation: 387

I believe you need to use cscript instead of wscript.

Do you show any change if you update

Shell "Wscript.exe " & strFileVB & " " & strUploadFile 'Here I tried to Run VB

To the following?

Shell "Cscript.exe " & strFileVB & " " & strUploadFile

https://ss64.com/vb/arguments.html

Upvotes: 1

Related Questions