我对vba和excel中的编程相当新,想要创建一个函数来进行化学描述并在SigmaAldrich的数据库中搜索CAS编号,但是我的函数没有返回任何值。我该怎么办?
Public Function Cas(ByVal cell1 As String) As String
Dim objIE As InternetExplorer
Dim aEle As HTMLLinkElement
Set objIE = New InternetExplorer
objIE.Visible = True
objIE.navigate "https://www.sigmaaldrich.com/united-states.html"
Do While objIE.Busy = True Or objIE.readyState <> 4: DoEvents: Loop
objIE.document.getElementById("Query").Value = cell1
objIE.document.getElementById("submitSearch").Click
If objIE.getElementsByClassName("Info") Then
If aEle Then
Cas = aEle.innerText
objIE.Quit
Exit Function
Else
Cas = "Manually Check"
objIE.Quit
Exit Function
End If
Else
Cas = "Manually Check"
objIE.Quit
End If
End Function
示例输入是
MOPS SODIUM SALT
应该产生输出
71119-22-7
相反,当我尝试使用该函数时,我得到了
的结果=会计准则(A1)