自动填充Internet Explorer输入框 - MSP中的VBA

时间:2016-05-03 12:43:04

标签: vba ms-project

您好我正在尝试在VBA中使用字符串填写网页上的自由文本字段。我的代码如下。

我在这里做错了什么?

Sub Testing()

Dim objIE As SHDocVw.InternetExplorer

Set objIE = New SHDocVw.InternetExplorer

objIE.Navigate "https://someaddress.com/somepath.do"
objIE.Visible = True
Do Until Not objIE.Busy And objIE.ReadyState = 4
    DoEvents
Loop

objIE.Document.getElementsById("#IO:c0242cf36ff09200b872129e5d3ee445.question_textarea_input cat_item_option").value = "Some String"

End Sub

网页上的Inspect元素如下

<textarea placeholder="Describe in detail the issue you are experiencing." style="overflow: hidden; word-wrap: break-word; resize: none; height: 64px;" rows="5" id="IO:c0242cf36ff09200b872129e5d3ee445" class="question_textarea_input cat_item_option" onchange="if (typeof(variableOnChange) == 'function') variableOnChange('IO:c0242cf36ff09200b872129e5d3ee445')" name="IO:c0242cf36ff09200b872129e5d3ee445" wrap="soft"></textarea>

任何帮助表示感谢。

1 个答案:

答案 0 :(得分:0)

我已经解决了这个问题,但谢谢你的帮助。

自由文字字段位于IFrame

Sub Testing()

Dim objIE As SHDocVw.InternetExplorer

Set objIE = New SHDocVw.InternetExplorer

objIE.Navigate "https://someaddress.com/somepath.do"
objIE.Visible = True
Do Until Not objIE.Busy And objIE.ReadyState = 4
    DoEvents
Loop

Set objIE = obj.Document.getElementID("anIFrame")
objIE.Document.getElementByID("IO:c0242cf36ff09200b872129e5d3ee445").value = "Some String"

End Sub