使用excel vba错误在IE中输入文本

时间:2016-05-13 23:06:51

标签: excel vba excel-vba internet-explorer

我一直在尝试使用VBA在IE中输入文本,但我不断得到对象不支持此属性 我试图输入测试的网址是 http://www.smartsurvey.co.uk/s/2XKL1/

我的代码是

Sub inputusername()
Dim IE As Object
Dim name As String


With Application
    .ScreenUpdating = False
    .EnableEvents = False
End With

currenttime = Hour(Now())

If currenttime < 12 Then
    g01 = "Morning"
ElseIf currenttime >= 18 Then
    g01 = "Evening"
Else
    g01 = "Afternoon"
End If
'Me.embtn.Visible = True
'MsgBox (g01 & " " & Application.UserName)
If MsgBox(g01 & " " & Application.UserName & " Please input your name on the website?", vbYesNo + vbQuestion) = vbNo Then
    name = InputBox("Please type in your name")
Else
    name = Application.UserName
End If
'MsgBox (Name)
Set IE = CreateObject("InternetExplorer.Application")
With IE

    .Visible = True
    .Navigate ("http://www.smartsurvey.co.uk/s/2XKL1/")
    Do While IE.Busy: DoEvents: Loop

    IE.doucment.getelementsByName("t31092740").innertext = name
    IE.document.getelementsByName("cmdGo").Item.Click
End With
' cleaning up memory
IE.Quit
Set IE = Nothing

MsgBox "Yippy Thanks"

End Sub

我试过替换IE.doucment.getelementsByName("t31092740").innertextIE.doucment.getelementsByName("t31092740").innerhtml; IE.doucment.getelementsByID("t31092740").innertext但保持geting对象不支持此属性或方法

1 个答案:

答案 0 :(得分:0)

1-需要使用物品(或第一项使用......(&#34; t31092749&#34;)(0).Value)

2-需要使用Value属性

尝试:

IE.document.getElementsByName("t31092740").Item.Value = name

注意:它是&#34;文件&#34;当然。我认为你的代码中是拼写错误。