【发布时间】:2020-09-11 09:00:38
【问题描述】:
我正在处理网页并使用 VBA 单击“浏览”按钮。 功能是上传文件。因此,当单击浏览按钮时,浏览窗口将打开,并且必须输入文件路径名。
我正在从 Excel 工作表中复制路径名称并尝试将其粘贴到“浏览”窗口中。
我的问题是我无法将文件路径名粘贴到浏览窗口中。
点击按钮后的行直到我没有手动干预并在浏览窗口中输入路径才会执行。
我想粘贴路径名并按 Enter 以便接受该路径。
HTML 代码如下所示:
<input type = "file" id="Browse_ID"....>
我的 VBA 代码在 tagx 之后停止。单击并等待手动输入:
set ieDoc = ieApp.document
set Tags = ieDoc.getElementsByTagName("input")
For Each tagx in Tags
If tagx.ID = "Browse_ID" Then
'Copy data to be pasted in Browse dialogue box
ActiveWorkbook.Sheets("Sheet7").Range("D11").Select
Selection.Copy
'Click on Browse
tagx.Click
'Paste by sending keys control v
SendKeys "{^v}"
'Send Enter key so that the path of the file that is entered is accepted and
'dialogue box closes
SendKeys "~"
exit For
End IF
Next
我尝试使用 Do while,但也没有用:
'Copy data to be pasted in Browse dialogue box
ActiveWorkbook.Sheets("Sheet7").Range("D11").Select
Selection.Copy
Do while (tagx.Click = True)
'Paste by sending keys control v
SendKeys "{^v}"
'Send Enter key so that the path of the file that is entered is accepted and
'dialogue box closes
SendKeys "~"
Loop
请帮忙!
【问题讨论】:
-
你能给我看看链接吗?
-
该网站仅限于我公司的员工。 :( 我只是在检查是否有具有类似属性的站点。找到一个。不确定它的作用。使用它时要小心:“megafileupload.com”。您可以使用任何具有文件上传选项的站点并且它的 HTML 代码和我提到的一样。
-
The page you are looking for cannot be found -
如果我没记错的话,那么在这种情况下,您将不得不使用 API。见THIS你得用类似的逻辑