自动执行我的网站时出现错误“被调用的对象已从客户端断开连接”

以下是我正在使用的代码

Sub IE_try() Application.ScreenUpdating = False Set IE = CreateObject("InternetExplorer.Application") IE.Visible = True IE.Navigate "my site" Application.StatusBar = "Submitting" While IE.Busy DoEvents Wend delay 5 IE.Document.getElementByClass("ms-textSmall ms-srch-sb-prompt ms-helperText").Value = "abc" IE.Documnet.getElementByName("ms-srch-sb-searchImg").Click End Sub 

错误信息:

提前致谢 :)

你正在得到一个奇怪的错误。 一般来说你的代码有点不对,你应该使用getElementsByClassname而不是getElementsByClass 。 这里有一些开始,为StackOverflow网站工作,在search引擎中编写abv

 Option Explicit Sub IE_try() Dim Element As Object Dim IE As Object Set IE = CreateObject("InternetExplorer.Application") IE.Visible = True IE.Navigate "http://stackoverflow.com" While IE.Busy DoEvents Wend Set Element = IE.Document.getElementsByClassname("f-input js-search-field") Element.Item.Value = "abv" End Sub