Results 1 to 6 of 6

Help click on link javascript webpage

Threaded View

  1. #4
    Forum Contributor
    Join Date
    08-01-2012
    Location
    Tampa
    MS-Off Ver
    Excel 2010
    Posts
    121

    Re: Help click on link javascript webpage

    well then, if you intend to fill out forms and stuff you will definitely need to learn how to use DOM. DOM lets VB see everything about the webpage, then you tell it where you want to edit information. You will start to think of it as automating excel from VBA btw (not the other way around). Im currently stuck on a VBA issue using DOM, and this forum's strength doesn't seem to really be in the programming, especially for web forms.

    http://stackoverflow.com/questions/7...sing-excel-vba


    You need to go to tools > References and check "Microsoft HTML Object Library" as well as "Microsoft Internet Controls"

    Disclaimer: Im very new to this

    I would modify that code like so (I dont like that browser time out stuff, but keep in mind this script will loop until the browser is "DONE" loading the page, so if its a busy server, it wont know when to stop):

    
    
    Sub Test()
    Dim Browser As SHDocVw.InternetExplorer
    Dim HTMLDoc As MSHTML.HTMLDocument
    
        Set Browser = New SHDocVw.InternetExplorer                     ' create a browser
        Browser.Visible = True                                         ' make it visible
        Application.StatusBar = ".... opening page"
        Browser.navigate "http://www.google.com"                       ' navigate to page
        
        Do Until Browser.readystate = 4
        DoEvents
        Loop                                     ' wait for completion or timeout
    
        Application.StatusBar = "gaining control over DOM object"
        Set HTMLDoc = Browser.document                                 ' load the DOM object
        
       
        Do Until Browser.readystate = 4
        DoEvents
        Loop
        
    
        ' at this point you can start working with the DOM object. Usefull functions are
        '     getElementByID(string)
        '     getElementsByTagName(string)
        '     getElementsByName(string)
        '     getAttribute(string)
        '     .setAttribute string, string     .... to change field values, click a button etc.
    
        
    With HTMLDoc
    
     
    
    'This is where you need to figure out your id tags, each id tag should be unique to each name, i would try:
    
    getelementbyID("dg_census__ctl13_AppLink"). 
    
    End With
    
    
        Application.StatusBar = ""                                      ' time to clean up
        Browser.Quit
        Set HTMLDoc = Nothing
        Set Browser = Nothing
    End Sub
    once you hit that . it will give you a full range of methods to do. You should figure out how to select it and click it, which im not entirely sure about (you can google, but most of the stuff will be about javascript. From what I understand, it will be similar because the DOM is universal), you might be able to do .click at the end of it. With the lack of support Ive gotten for my web button issue, im thinking this will probably be your only bet, but it is the right way to do it (through DOM). The problem wont be so much doing it, its telling VB what to select and take control of. But luckily using the WITH tag in that sense, when you finally figure it out and get to the forms part, you can set the form data from variables all at once. This is intermediate stuff, so dont be surprised if you dont fully see it or understand, you just need to keep playing with it and thinking of ideas.
    Last edited by jayinthe813; 09-05-2012 at 11:42 PM.

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