+ Reply to Thread
Results 1 to 6 of 6

Help click on link javascript webpage

Hybrid View

rickmdz Help click on link javascript... 09-05-2012, 07:23 PM
jayinthe813 Re: Help click on link... 09-05-2012, 08:13 PM
rickmdz Re: Help click on link... 09-05-2012, 08:21 PM
jayinthe813 Re: Help click on link... 09-05-2012, 08:35 PM
rickmdz Re: Help click on link... 09-06-2012, 01:39 AM
jayinthe813 Re: Help click on link... 09-06-2012, 11:59 PM
  1. #1
    Registered User
    Join Date
    09-04-2012
    Location
    california
    MS-Off Ver
    Excel 2010
    Posts
    3

    Help click on link javascript webpage

    I'm a total newbie when it comes to VBA, I'm learning a lot on this website.

    The problem I have I can't click a link on a website with javascript on it. It's a page in my intranet so I can't provide a link. I have person names on Excel and want to access a website cliking on the names of those persons.

    Here is the source portion from the webpage, the 'XXXXXXXXXX' is the specific name with 20-30 similar on each page, so the idea is get the name from excel and click on the appropiate link.

    <a id="dg_census__ctl13_AppLink" href=",DanaInfo=10.32.112.141+patientdos.aspx?mrn=737300&amp;ntlogid=YYYYYYY&amp;Adm_Date=8/29/2012&amp;LastSeen=8/30/2012&amp;PatName=XXXXXXXXXXX&amp;LastSubmission=&amp;RealAdmDate=8/26/2012" target="_parent" style="color:#0000CC;width:80px;">XXXXXXXXX</a>
    The
    And this is what I have so far

    Sub Census()
    Dim ie As Object
    Dim url As String
    Dim PersonN As String
    
    
        url = "https://access.............."
            Set ie = CreateObject("internetexplorer.application")
            ie.Visible = True
            ie.navigate url
            
            While ie.Busy Or ie.readyState <> 4
                DoEvents
            Wend
        ie.Document.getelementbyid("rbl_DateRange_0").click
        While ie.Busy Or ie.readyState <> 4
                DoEvents
            Wend
    
        PersonN = Sheets("Sheet1").Range("A1").Value 'get name from Excel sheet
        
        'Need to click on a link with that persons name HELP!
        
    
        
    End Sub
    TIA

    Rick

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

    Re: Help click on link javascript webpage

    why not just make the href directly to that person? as in, instead of clicking it, use the referring link directly in excel

    and where the XXXXXX's exist you replace that with the name you intended to click on. It seems that you can edit the URL to bring back the results you need rather than relying on a click, else am i missing something?

    Lets say the link was


    <a href="google.com/XXXX">XXXX</a>
    You could just go ahead and launch your browser to point to:

    url = "http://google.com/gina"
    ..
    ..
    ie.navigate url

    additionally, you could point that through excel by doing:

        Range("A1").Select
        ActiveCell.FormulaR1C1 = "=HYPERLINK(""http://google.com/gina"",""Gina"")"
    this should create the name Gina, in A1, with the hyperlink as it appears. The way you would have to select and click, would be to create references to MSHTML, and let VBA parse the info, then use .getelement to grab the ID of the field, select, and then click
    Last edited by jayinthe813; 09-05-2012 at 08:18 PM.

  3. #3
    Registered User
    Join Date
    09-04-2012
    Location
    california
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Help click on link javascript webpage

    I'm trying to automate the process using vba from excel. That link will open another page with a form that needs to be filled with data from excel, then loop through every name on the list.
    I'm trying to figure out the navegation part first as the rest would be easier (I think)

  4. #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.

  5. #5
    Registered User
    Join Date
    09-04-2012
    Location
    california
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Help click on link javascript webpage

    I found the solution

    Set ElementCol = appIE.Document.getElementsByTagName("a")
     
    For Each Link In ElementCol
        If Link.innerHTML = "Clickable Text Link Name" Then
            Link.Click
            Exit For
        End If
    Next Link
    Instead of "clickable text" I'm using a variable (PersonN) that gets each name from excel

    Found the solution here http://www.codeforexcelandoutlook.co...rnet-explorer/

    Thank you jayinthe813! You pointed me in the right direction
    Last edited by rickmdz; 09-06-2012 at 01:41 AM.

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

    Re: Help click on link javascript webpage

    great job on figuring that out by the way :D
    Last edited by Cutter; 09-07-2012 at 03:53 PM. Reason: Removed whole post quote

+ 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