+ Reply to Thread
Results 1 to 10 of 10

How to check if a object exist on a HTML Document

  1. #1
    Registered User
    Join Date
    01-14-2013
    Location
    Londo, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    How to check if a object exist on a HTML Document

    well im trying to make a macro that access a web and completes User and password if the user is not logged in, i want to know if there is a way to determine if an object exist in a html, because im receiving an error from the script when the macro tries to click the connect button and the button is not in the html (this happens when the user is already logged).

    i already try something like setting an object with the "GetelementById" and then use IsNothing, but when the script processes "GetElementById" it sends an error of object not found, or process not available.

  2. #2
    Registered User
    Join Date
    01-14-2013
    Location
    Londo, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: How to check if a object exist on a HTML Document

    Please, i need a little help with this!

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    What code do you have?
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    01-14-2013
    Location
    Londo, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: How to check if a object exist on a HTML Document

    im setting the user and pass like this:


    With ieDoc.frames.Item(1).document.getElementById("topaz")
    .document.getElementById("X30").Value = Worksheets(actSheet).Range("B4").Value
    .document.getElementById("X44").Value = Worksheets(actSheet).Range("B5").Value
    .document.getElementById("X88").Click
    end with

    i have tried putting something like
    set obj = .document.getElementById("X88")

    and then
    If obj is not nothing then
    With ieDoc.frames.Item(1).document.getElementById("topaz")
    .document.getElementById("X30").Value = Worksheets(actSheet).Range("B4").Value
    .document.getElementById("X44").Value = Worksheets(actSheet).Range("B5").Value
    .document.getElementById("X88").Click
    end with

    but it crushes when the macro trys to get the button, i only want to click a button in a html if it exists.

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

    Re: How to check if a object exist on a HTML Document

    Instead of clicking the button you could submit the form.
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    01-14-2013
    Location
    Londo, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: How to check if a object exist on a HTML Document

    ok, buts that is not the problem because now i will have an error in
    .document.getElementById("X44").Value = Worksheets(actSheet).Range("B5").Value

    because if im not in the "login screen" i dont have the X44

    thanks for your reply!

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

    The code I'm suggesting would go after the code to enter the username and password

  8. #8
    Registered User
    Join Date
    01-14-2013
    Location
    Londo, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: How to check if a object exist on a HTML Document

    because the variable only exist in the same page of the button, so if you do this:
    .document.getElementById("X44").Value = Worksheets(actSheet).Range("B5").Value
    you have an error of Object Variable or With Block variable not set...

  9. #9
    Registered User
    Join Date
    01-14-2013
    Location
    Londo, England
    MS-Off Ver
    Excel 2003
    Posts
    8

    Re: How to check if a object exist on a HTML Document

    the problem is that i only have to click the button and complete the values of the variables if im in a certaing page soy i need to know if the exist before completing them

  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: How to check if a object exist on a HTML Document

    I don't follow what you mean, what objects are you referring to?

    If they aren't being found on the page it's nothing to do with the code I posted.

    Have you tried the code?
    Please Login or Register  to view this content.

    Can you post the URL for the login page?

    One thing I would recommend doing is creating references to the various objects as you go.

    For example to create a reference to the frame an to 'topaz'.
    Please Login or Register  to view this content.
    Last edited by Norie; 01-15-2013 at 02:22 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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