我正在使用带有一列许可证编号的工作表的 excel 2013。
宏需要循环浏览网页上要搜索的每个单元格。搜索后,它会从搜索结果页面中获取一些详细信息,并将其放在许可证号旁边的单元格中。
我遇到的问题是,并不是所有的许可证号都会被找到,这会导致网站抛出错误,并且不会进入导致代码失败的结果页面。
我需要一种方法来跳过引发网页错误的许可证号并继续到下一个条目。
另一个更令人头疼的问题是,插入到单元格中的结果来自表格格式,因此它使单元格变得庞大并摆脱了工作簿格式。有没有办法从搜索结果中仅获取特定细节或确保将其置于“未包装”格式?
重新创建宏的详细信息。
该网站需要您创建一个免费的用户名和密码,但创建后应该保存一个 cookie,因此代码不包含登录部分。
网页搜索位置(登录后):https ://aca3.accela.com/MILARA/GeneralProperty/PropertyLookUp.aspx?isLicensee=Y&TabName=APO
错误页面:https ://aca3.accela.com/MILARA/Error.aspx?ErrorId=2d09a60802d2455b8fbf1b86e45033d2
Sub SearchPage()
Dim IE As Object
Dim search As Variant
Dim button As Variant
Dim LR As Integer
Dim var As String
Dim var1 As Object
Dim CurrentWindow As HTMLWindowProxy
LR = Cells(Rows.Count, 1).End(xlUp).Row
For x = 2 To LR
var = Cells(x, 1).Value
Set IE = CreateObject("internetexplorer.application")
IE.Visible = True
With IE
.Visible = True
.navigate "https://aca3.accela.com/MILARA/GeneralProperty/PropertyLookUp.aspx?isLicensee=Y&TabName=APO"
While Not .readyState = READYSTATE_COMPLETE
Wend
End With
'Wait some to time for loading the page
While IE.Busy
DoEvents
Wend
Application.Wait (Now + TimeValue("0:00:02"))
'this is where it puts the number from the cell into the search box
'below is the text search box and the cell containing the ID IE.document.getElementById("ctl00_PlaceHolderMain_refLicenseeSearchForm_txtLicenseNumber").Value = var
'Here we are clicking on search Button
IE.document.getElementById("ctl00_PlaceHolderMain_btnNewSearch").Click
'wait for page to load
Application.Wait (Now + TimeValue("0:00:02"))
While IE.Busy
DoEvents
Wend
'grabs results from search and places it in cell next to searched id
Set var1 = IE.document.getElementById("ctl00_PlaceHolderMain_upGeneralInfo")
Cells(x, 2).Value = var1.innerText
IE.Quit
Set IE = Nothing
Next x
End Sub