gpt4 book ai didi

windows - VBA:IE-如何在没有弹出文件上传表单的情况下将路径名分配给文件输入标签?

转载 作者:可可西里 更新时间:2023-11-01 10:55:47 37 4
gpt4 key购买 nike

我目前正在做文件上传的自动化

下面是输入文件标签的 HTML 标签:

 <input name="file" title="Type the path of the file or click the Browse button to find the file." id="file" type="file" size="20">

下面是按钮 HTML 标签:

<input name="Attach" title="Attach File (New Window)" class="btn" id="Attach" onclick="javascript:setLastMousePosition(event); window.openPopup('/widg/uploadwaiting.jsp', 'uploadWaiting', 400, 130, 'width=400,height=130,resizable=no,toolbar=no,status=no,scrollbars=no,menubar=no,directories=no,location=no,dependant=no', true);" type="submit" value="Attach File">

我的 VBA 编码是:

Dim filee As Object
Set filee = mydoc.getElementById("file")
filee.Value = filenamepath

Set attach = mydoc.getElementsByName("Attach")
attach(0).Click

当我运行此编码时,输入文件路径框未分配路径名,因此我选择了文件路径。

查找附件截图。 enter image description here

最后我尝试了下面的代码但是发送键没有执行

Dim filee As Object
Set filee = mydoc.getElementById("file")
filee.Click

obj.SetText filename
obj.PutInClipboard
SendKeys "^v"
SendKeys "{ENTER}"

Set attach = mydoc.getElementsByName("Attach")
attach(0).Click

Set finall = mydoc.getElementsByName("cancel")
finall(0).Click

请告诉我 Windows API 程序在打开的 Choose File to Open 资源管理器上的 fine name: 输入框中分配我的文件名目录,然后单击 open 按钮。

最佳答案

我通过运行包含文件路径的外部 VBScript 解决了这个问题,在发送 Enter 键关闭此弹出窗口后使用 SendKeys 方法将其设置在“选择要上传的文件”弹出窗口上,并且此运行成功,因为 extranl VBScript 运行于另一个进程,因此它不会停留在 VBA 代码上。

注意事项:1- 我从 VBA 代码动态创建外部 VBScript 并将其保存在 Temp 文件夹中,然后我使用 WScript.Shell.Run 运行此脚本以在另一个线程上执行它1- 在外部 VBScript 开始时,我设置了 1 秒的延迟,以确保“选择要上传的文件”弹出窗口已经从 VBA 打开。

完整代码如下:

....
....

Set filee = mydoc.getElementById("file")

CompleteUploadThread MyFilePath
filee.Foucs
filee.Click

....
....

Private Sub CompleteUploadThread(ByVal fName As String)
Dim strScript As String, sFileName As String, wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
'---Create VBscript String---
strScript = "WScript.Sleep 1000" & vbCrLf & _
"Dim wsh" & vbCrLf & _
"Set wsh = CreateObject(""WScript.Shell"")" & vbCrLf & _
"wsh.SendKeys """ & fName & """" & vbCrLf & _
"wsh.SendKeys ""{ENTER}""" & vbCrLf & _
"Set wsh = Nothing"
'---Save the VBscript String to file---
sFileName = wsh.ExpandEnvironmentStrings("%Temp%") & "\zz_automation.vbs"
Open sFileName For Output As #1
Print #1, strScript
Close #1
'---Execute the VBscript file asynchronously---
wsh.Run """" & sFileName & """"
Set wsh = Nothing
End Sub

关于windows - VBA:IE-如何在没有弹出文件上传表单的情况下将路径名分配给文件输入标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34803863/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com