+ Reply to Thread
Results 1 to 15 of 15

getElementsByClassName from Yammer causing Run-time error 91

  1. #1
    Registered User
    Join Date
    03-20-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    27

    getElementsByClassName from Yammer causing Run-time error 91

    Hi,

    I am trying to get some information about Yammer groups. Using the video tutorial in the link below I have modified the code to get the number of members from a yammer groups page. I am getting the error message "Run time error '91': Object variable or With block variable not set". If I then click debug, and carry on running the program it works fine as if there was never an error. It also works if I put a breakpoint on the line "sMembers = Trim(Doc.getElementsByClassName("yj-count")(1).innerText)" and then step past it, it jsut wont run all in one go. Despite searching the problem I have no idea what the problem could be.

    http://www.youtube.com/watch?v=7sZRcaaAVbg

    The code I am using is:

    Please Login or Register  to view this content.
    Thanks in advance for your help,

    Regards,

    Geraint

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: getElementsByClassName from Yammer causing Run-time error 91

    I think the page hasn't finished loading, at a guess the page is javascript heavy. You're getting the message since at the time you run the line of code, the page hasn't fully rendered, but by the time you have hit debug, it's finished rendering

    You could make your code wait longer before continuing, I suspect that it would solve the issue

  3. #3
    Registered User
    Join Date
    03-20-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: getElementsByClassName from Yammer causing Run-time error 91

    Thanks Kyle. Is there a way of making it wait until it's fully loaded, and isn't that what happens in "Loop Until IE.readyState = READYSTATE_COMPLETE"?

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: getElementsByClassName from Yammer causing Run-time error 91

    Not that I'm aware of, Readystate_complete is triggered when all the resources are downloaded. Since most javascript will use this as a trigger to begin execution, your code is running concurrently.

    I suppose you could keep a doevents loop running and check for the existence of the class in the loop, once it's found exit the loop. Would that work for you?

  5. #5
    Registered User
    Join Date
    03-20-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: getElementsByClassName from Yammer causing Run-time error 91

    Yes, that would work. How would I go about putting the check in, and would there be a way of putting a time limit on it as well so if for some reason the class never loads it won't get stuck in an endless loop? Perhaps something like the following?

    LOOP UNTIL class exists OR timer = 15s

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: getElementsByClassName from Yammer causing Run-time error 91

    maybe something like:
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    03-20-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: getElementsByClassName from Yammer causing Run-time error 91

    So close! Just using the Now > oNow part works but is obviously slow. When I add the "OR" check for the length > 0 i get the same error as before becasue the class doesn't exist to check it's length.

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: getElementsByClassName from Yammer causing Run-time error 91

    Instead of checking the length, check for it's existence/non-existence using Is Nothing.
    If posting code please use code tags, see here.

  9. #9
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: getElementsByClassName from Yammer causing Run-time error 91

    I think there's something else here Norie, that line will never return nothing - even if it doesn't match a class it will still exist - it will just have a length of zero.

    Which version of IE are you running?

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: getElementsByClassName from Yammer causing Run-time error 91

    Using Is Nothing has worked for me in the past, in various versions of IE and with various getElement(s) methods.

    One thing I've also used is a loop to check the document has completed loading.

    Perhaps that could help here.

  11. #11
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: getElementsByClassName from Yammer causing Run-time error 91

    How would you loop to check if the document has finished loading? I'm only asking since I don't know how this would be possible - sure if it were a case of the DOM rendering from the initial call, READYSTATE_COMPLETE would be fine, but javascript which adds to the DOM executes after this event has already fired.

    Despite my (admittedly limited) testing with the getElementsbyClassName method, I cannot get it to return nothing, even if the classes are not on the page - it returns an empty collection with a length of 0. I'm running IE10 on windows7, maybe it's different in earlier browsers, but it wasn't even available until IE9

  12. #12
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: getElementsByClassName from Yammer causing Run-time error 91

    What I mean is checking to see if IE is still 'busy' with the document.
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    03-20-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: getElementsByClassName from Yammer causing Run-time error 91

    Perfect! "Nothing" worked, I changed the line to the following:

    HTML Code: 
    Thank you both so much for your help.

  14. #14
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: getElementsByClassName from Yammer causing Run-time error 91

    Glad you got it sorted

    Its oddv behaviour though, are you running ie9 out of interest?

  15. #15
    Registered User
    Join Date
    03-20-2012
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: getElementsByClassName from Yammer causing Run-time error 91

    Yes I am, IE9.

    Thanks,

    Ger

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1