VBA:IE-如何分配路径到文件输入标签没有弹出文件上传表单? [英] VBA:IE-How to assign pathname to file input tag without popup file upload form?

查看:473
本文介绍了VBA:IE-如何分配路径到文件输入标签没有弹出文件上传表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在做automaiton文件上传

I am currently doing automaiton for file uploading

下面是输入文件标记HTML标记:

Below is HTML tag for input file tag:

 <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标签:

And below is button HTML Tag:

<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代码是:

My VBA coding is:

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

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

当我运行这种编码,输入文件路径框没有,所以我选择了获取文件路径指定路径名。

When I am running this coding, input filepath box not assign path name so i am getting chose file path.

查找附上截图。

最后我都试过低于code但发送键不执行

Finally i have tried below code but that send key not executing

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的程序来分配我的文件名,目录中的精细名称:输入框中打开选择要打开的文件资源管理器,然后点击打开按钮。

Kindly tell me the windows API program to assign my file name directory in fine name: input box on opened Choose File to Open explorer and click the open button.

推荐答案

作为设置文件输入元素的值被禁用,由于安全原因,发送键的方法似乎是使用自动文件上传的唯一选择IE的API。

As setting the value of a file input element is disabled due to security reasons, the "send keys" method seems to be the only option for automating file uploads using the IE API.

我只是偶然在同一个问题,即code后点击似乎并没有被执行 - 也就是说,除非对话框被关闭。这表明点击方法拦截,使其无法与对话从宏观范围内进行互动。

I just stumbled over the same problem that the code after the Click does not seem to be executed - that is, unless the dialog is closed. This indicates that the Click method is blocking, making it impossible to interact with the dialog from within the macro.

我可以解决,通过使用不同的方法来打开对话框:通过设置集中到文件中的元素与焦点,并用<$ C发送空格键$ C>的SendKeys 。

I could solve that by using a different method to open the dialog: by setting the focus to the file element with Focus, and sending the space key with SendKeys.

在你的情况下,更换

filee.Click

filee.Focus
SendKeys " "

这篇关于VBA:IE-如何分配路径到文件输入标签没有弹出文件上传表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆