VBA to control an open webpage

fredrerik84

Active Member
Joined
Feb 26, 2017
Messages
383
Hi guys im trying to control an webpage that is already open but so far im not able to get it to work.
here is what I have:

Code:
Sub google()


    Dim IE As New SHDocVw.InternetExplorer
    Dim HTMLDoc As New MSHTML.HTMLDocument
    Dim HTMLRows As MSHTML.IHTMLElementCollection
    Dim HTMLRows2 As MSHTML.IHTMLElementCollection
    Dim HTMLRows3 As MSHTML.IHTMLElementCollection
    Dim HTMLRows4 As MSHTML.IHTMLElementCollection
    Dim HTMLRows5 As MSHTML.IHTMLElementCollection
    Dim HTMLRow As MSHTML.IHTMLElement
    Dim Doc As HTMLDocument
    Dim i As Long
    Dim j As Long
    Dim k As Long
    Dim x As Long
    Dim lr As Long
    Dim Url As String
    Dim matched As String
    Dim wb As Worksheet
    Set wb = ActiveWorkbook.sheets("Conversion")
    Dim mycur As String
    Dim marker As Long
    Dim objShell
    Dim IE_count
    Dim my_url
    Dim my_title
    
    marker = 0
    Set objShell = CreateObject("Shell.Application")
    IE_count = objShell.Windows.Count
    For x = 0 To (IE_count - 1)
       On Error Resume Next    ' sometimes more web pages are counted than are open
       my_url = objShell.Windows(x).******************
       my_title = objShell.Windows(x).document.Title


       If my_title Like "https://www.google.no/?gfe_rd=cr&ei=laCBWeyuEeXk8AeflIGgDw" & "*" Then 'compare to find if the desired web page is already open
          Set IE = objShell.Windows(x)
          marker = 1
       Exit For
       Else
       End If
     Next
    
    If marker = 0 Then
       MsgBox ("A matching webpage was NOT found")
    Else
       MsgBox ("A matching webpage was found")
    End If
    
    End Sub

I found this code trough a google search but I can not get it to work ., Is there a brilliant mind in here that maybe could give a few pointer to what im doing wrong?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).

Forum statistics

Threads
1,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top