如何在 vba Excel 中自动上传文件 "Choose File To Upload"
How To Automate Upload File "Choose File To Upload" in vba Excel
我在 Internet Explorer 中自动上传文件时遇到问题。我在 VB 中也有文件,它名为 Upload.vbs.
错误图片:
点击浏览按钮的代码:
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)
strFileVB = "E:\Upload\Upload.vbs"
strUploadFile = "E:\Data21\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
如有任何帮助,我们将不胜感激。谢谢
我认为您需要使用 cscript 而不是 wscript。
更新后有没有变化
Shell "Wscript.exe " & strFileVB & " " & strUploadFile 'Here I tried to Run VB
给下面的?
Shell "Cscript.exe " & strFileVB & " " & strUploadFile
我在 Internet Explorer 中自动上传文件时遇到问题。我在 VB 中也有文件,它名为 Upload.vbs.
错误图片:
点击浏览按钮的代码:
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)
strFileVB = "E:\Upload\Upload.vbs"
strUploadFile = "E:\Data21\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
如有任何帮助,我们将不胜感激。谢谢
我认为您需要使用 cscript 而不是 wscript。
更新后有没有变化
Shell "Wscript.exe " & strFileVB & " " & strUploadFile 'Here I tried to Run VB
给下面的?
Shell "Cscript.exe " & strFileVB & " " & strUploadFile