2013-04-30 111 views
0

我正在使用的网页上有60到100个菜单链接,具体取决于用户凭据。我用这个代码,点击菜单链接:Excel VBA查找网页链接ID

Set oapp = CreateObject("Shell.Application") 
     For i = 0 To 25 
     StrName = "" 
     On Error Resume Next 
     StrName = oapp.Windows(i).Document.URL 
     If InStr(StrName, "mywebaddress.aspx") Then 
     Set oie = oapp.Windows(i) 
     Exit For 
     End If 
     Next 
     oie.Document.all("ctl11_repeaterNavigator_ctl32_menuLink").Click 

,而是根据用户凭据的链接数量的变化 - 与我的凭据_ctl32可以在别人_ctl32或_ctl33。有没有办法搜索内部文本并将链接ID存储为字符串?

I know I can click on the link by using: 
For i = 1 To oie.Document.all.Length 
If oie.Document.all.Item(i).innerText = "Letters" Then 
oie.Document.all.Item(i).Click 
Exit For 
End If 
Next i 

,但我需要一个字符串中的链接ID店下一步

+0

“oie.Document”中的每个元素都有一个'innerHTML'和'innerText'属性你知道菜单链接的'TagName'吗?或“名称”? – 2013-04-30 18:27:57

+0

@DavidZemens字母 – user2336998 2013-04-30 18:35:46

+0

你有没有机会尝试我的建议? – 2013-05-05 02:46:59

回答

0

也许尝试这样的事情,假设链接的Name是“字母”,并假定前缀“ctl11_repeaterNavigator_”和足够的“_menuLink”不会为用户改变。

Dim ele as Variant 
Dim parseString as String 

'## Determine what ctl to use:' 

For each ele in oie.Document.GetElementsByName("Letters") '## Modify to use the Name associated with this menu link ' 
    If Right(ele.InnerHTML,9) = "_menuLink" AND _ 
     Left(ele.InnerHTML, 24) = "ctl11_repeaterNavigator_" Then 
     ele.Click 
     Exit For 
    End If 
Next 

可能需要使用的ele.InnerText代替.InnerHTML因此,如果上述方法无效,请尝试调整它一下。