如何在 vba Excel 中自动上传文件“选择要上传的文件”

时间:2021-02-12 10:25:53

标签: excel vba vbscript

我在 Internet Explorer 中自动上传文件时遇到问题。我在 VB 中也有文件,它命名为 Upload.vbs。

错误图片:
enter image description here

点击浏览按钮的代码:

        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)

以下是 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

任何帮助将不胜感激。谢谢

1 个答案:

答案 0 :(得分:1)

我相信您需要使用 cscript 而不是 wscript。

如果您更新,您是否显示任何更改

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

以下?

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

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

相关问题