Results 1 to 1 of 1

VBA code to open links on browser

Threaded View

  1. #1
    Registered User
    Join Date
    01-09-2012
    Location
    mumbai
    MS-Off Ver
    Excel 2007
    Posts
    3

    VBA code to open links on browser

    Hi,

    Please help me as i am stuck at one point where i want my code to open another link after opening the first one.

    my code works well till the first link is opened for the second one it does not work.
    pls suggest me what to do.




    Sub GoToWebSiteAndPlayAround()
    
    Dim appIE As Object ' InternetExplorer.Application
    Dim sURL As String
    Dim UserN As Object ' MSHTML.IHTMLElement
    Dim PW As Object ' MSHTML.IHTMLElement
    Dim Element As Object ' HTMLButtonElement
    Dim btnInput As Object ' MSHTML.HTMLInputElement
    Dim ElementCol As Object ' MSHTML.IHTMLElementCollection
    Dim ElementCol2 As Object ' MSHTML.IHTMLElementCollection
    Dim Link As Object ' MSHTML.HTMLAnchorElement
    Dim strCountBody As String
    Dim lStartPos As Long
    Dim lEndPos As Long
    Dim TextIWant As String
    
    Dim fdate As String
    fdate = Sheet1.Cells("2", "H")
    
    Application.ScreenUpdating = False
    
    Set appIE = CreateObject("InternetExplorer.Application")
    
    sURL = "https://downloads.theice.com/Settlement_Reports/"
    
    With appIE
        .navigate sURL
        ' uncomment the line below if you want to watch the code execute, or for debugging
       .Visible = True
    End With
    
     'loop until the page finishes loading
    Do While appIE.Busy
    DoEvents
    Loop
    
    
    ' click a text link on the page after that
    
    
    Set ElementCol = appIE.document.getElementsByTagName("a")
    
    For Each Link In ElementCol
        If Link.innerHTML = "Gas/" Then
            Link.Click
            Exit For
        End If
    Next Link
    
    Set ElementCol2 = appIE.document.getElementsByTagName("a")
    
    For Each Link In ElementCol2
    
        If Link.innerHTML = "ngxcleared_gas_" & fdate Then
            Link.Click
            MsgBox ("done")
            Exit For
            MsgBox ("Not done")
        End If
    Next Link
    
    ' loop until the page finishes loading
    Do While appIE.Busy
      DoEvents
    Loop
    
    End Sub
    Last edited by pike; 01-09-2012 at 04:29 AM. Reason: add code tags for newbie

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