我正在尝试编写一个vba脚本来打开一个网站,导航到一个特定的记录,获取协议编号的值并将其存储为变量,然后将变量值粘贴到工作表中。目前我有以下内容,除了粘贴到excel之外,它完成了所有必需的步骤。我还尝试在插入excel行之前插入一个“msgbox AGR”来检查值,然后弹出正确的值。
在最后一行代码中,我收到“错误不匹配”对话框。非常感谢任何帮助。
Sub ReturnAgrNumber()
Dim IE As Object
Set IE = CreateObject("internetexplorer.application")
Dim AGR As Variant
IE.Visible = True
IE.navigate "http://*************************************.aspx"
While IE.busy
DoEvents
Wend
IE.Document.getElementByID("txtUsername").Value = "*****"
IE.Document.getElementByID("txtPassword").Value = "*****"
While IE.busy
DoEvents
Wend
IE.Document.all("btnLogin").Click
While IE.busy
DoEvents
Wend
IE.Document.getElementByID("ctl00$GotoControl$txtJumpToRecord_Header").Value = "A213010"
While IE.busy
DoEvents
Wend
IE.Document.getElementByID("ctl00$GotoControl$ddJumpToRecord_Header").selectedIndex = 3
IE.Document.getElementByID("ctl00$GotoControl$ddJumpToRecord_Header").FireEvent ("onchange")
While IE.busy
DoEvents
Wend
IE.Document.all("ctl00_GotoControl_btnHeaderJumpTo").Click
While IE.busy
DoEvents
Wend
AGR = IE.Document.getElementByID("ctl00_mainContentPlaceHolder_HeaderTop_Agreements2_lblID").InnerText
Workbooks("test").Worksheets(Sheet1).Range("a1") = AGR
End Sub
答案 0 :(得分:1)
您错过了工作表名称周围的引号:
Workbooks("test").Worksheets(Sheet1).Range("a1") = AGR
应该是
Workbooks("test").Worksheets("Sheet1").Range("a1") = AGR