开发者

Snippet of code works on my PC, but not another person's

开发者 https://www.devze.com 2023-03-15 02:28 出处:网络
There is a bit 开发者_JAVA技巧of code I have written, which works on my PC, but doesn\'t work on someone else\'s. I am really confused.the code in question is

There is a bit 开发者_JAVA技巧of code I have written, which works on my PC, but doesn't work on someone else's. I am really confused.the code in question is

Dim temp As HtmlHtmlElement   
Dim s As String   
s = "2222222"   
For Each temp In html.getElementsByTagName("option")         
    If temp.getAttribute("value") = s Then             
    r.Offset(0, 1) = (temp.innerText)                  
    End If   
Next temp

r is a Range object that is passed to the sub. the variable html is an object that has been loaded with html from a webpage,using xmlHTTP

This code works fine on my pc, it finds the "option" tags in the html source , and then checks to see if the "value" attribute is equal to the string s. When I run it on someone elses pc , temp.getAttribute("value") returns a blank string, even though there is an attribute called value. The web page address is hard coded so its not that he's using the wrong URL I use excel 2007, he uses 2010

Anyone got any ideas? thanks


How have you declared and instantiated the html object?

For example, you say you're using xmlHTTP but is that the only option? Does your code try and Set html to "Microsoft.XMLHTTP" first and if not found then try "MSXML2.XMLHTTP" or even different version numbers ServerXMLHTTP30/ServerXMLHTTP60?

If so, perhaps the problem is that the specific reference hasn't been enabled and your fetching the webpage through different objects. Each of these can return a webpage slightly differently with different encoding, UPPER/LOWERCASE etc based on webserver settings and the object.

Edit: You may find this useful Using the right version of MSXML

0

精彩评论

暂无评论...
验证码 换一张
取 消