+ Reply to Thread
Results 1 to 10 of 10

How to stop the internet explore pop up ?

Hybrid View

  1. #1
    Registered User
    Join Date
    03-06-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    17

    How to stop the internet explore pop up ?

    I have this macro code , It works fine but while it is running internet explorer pops up all the time, Can anyone help to stop is popping up?

    I have attached the sheet .Reviews Mapping.xlsm
    Last edited by pari9485; 10-09-2013 at 01:24 PM.

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

    Re: How to stop the internet explore pop up ?

    Try changing the code that deals with the HTML to this, which works.
            Set htmlDoc = CreateObject("htmlfile")
                
            htmlDoc.body.innerhtml = PageSrc
            
                For Each htmlSpan In htmlDoc.getElementsByTagName("span")
                    If htmlSpan.ClassName = "partner-reviews-count" Then
                        If htmlSpan.NodeType = 1 Then
                            GetReviewsCount = Val(htmlSpan.innerhtml)
                            Exit Function
                        End If
                    End If
                Next htmlSpan
    
            GetReviewsCount = "No Review"
    Last edited by Norie; 10-09-2013 at 03:21 PM.
    If posting code please use code tags, see here.

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: How to stop the internet explore pop up ?

    Hello pari9485,

    I found the problem!

    The authors of the web page made a mistake in the code. The problem is with the placement of a META tag in the code. This tag tells Internet Explorer which version to use. Since it is in the wrong place, Internet Explorer defaults to version 7. Here are the updated macros. The attached file has them added.

    Function GetReviewsCount(ByVal URL As String) As Variant
          
        Dim htmlDoc     As Object
        Dim htmlSpan    As Object
        Dim i           As Long
        Dim metTag      As String
        Dim PageSrc     As String
        
            With CreateObject("MSXML2.XMLHTTP")
                .Open "GET", URL, True
                .Send
                                    
                While .readyState <> 4: DoEvents: Wend
                                
              ' Check for any connection errors. Put the error info in cells A4:B4.
                If .statusText <> "OK" Then
                    MsgBox "ERROR " & .Status & " - " & .statusText, vbExclamation
                    Exit Function
                End If
                                
                PageSrc = .ResponseText
            End With
            
            i = InStr(1, PageSrc, "<head>", vbTextCompare)
            If i = 0 Then Exit Function
            
            metaTag = " <meta http-equiv=""X-UA-Compatible"" content=""IE=edge,chrome=1""> "
            PageSrc = Left(PageSrc, i + 5) & metaTag & Right(PageSrc, Len(PageSrc) - i - 5)
    
          ' Create an empty HTML Document and load it with the PageSource.
            Set htmlDoc = CreateObject("htmlfile")
            htmlDoc.Open
            
          ' NOTE: This will check if cookies are enabled and prompt you if they aren't.
            htmlDoc.write PageSrc
          
          ' Close the file for writing.
            htmlDoc.Close
            
            While htmlDoc.readyState <> "complete": DoEvents: Wend
            
                For Each htmlSpan In htmlDoc.getElementsByTagName("span")
                    If htmlSpan.ClassName = "partner-reviews-count" Then
                        If htmlSpan.NodeType = 1 Then
                            GetReviewsCount = Val(htmlSpan.innerHTML)
                            Exit Function
                        End If
                    End If
                Next htmlSpan
    
            GetReviewsCount = "No Review"
            
    End Function
    
    Sub Macro1()
    
        Dim Cell    As Range
        Dim EndRow  As Long
        Dim Rng     As Range
        Dim Wks     As Worksheet
        
            Set Wks = ActiveSheet
            Set Rng = Wks.Range("A2")
            
                EndRow = Wks.Cells(Rows.Count, "A").End(xlUp).Row
                If EndRow < Rng.Row Then Exit Sub Else Set Rng = Rng.Resize(EndRow - Rng.Row + 1, 1)
                
                For Each Cell In Rng
                    DoEvents
                    Cell.Offset(0, 1) = GetReviewsCount(Cell)
                Next Cell
            
            MsgBox "Finished checking reviews."
            
    End Sub
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Registered User
    Join Date
    03-06-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: How to stop the internet explore pop up ?

    Wow, this is awesome, now I can finish my work in minutes Thanks a lot .

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

    Re: How to stop the internet explore pop up ?

    pari9485

    Just curious, did you try what I suggested?

  6. #6
    Registered User
    Join Date
    03-06-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: How to stop the internet explore pop up ?

    the code which you gave didn't help to solve the problem , but i got the solution. Thanks for the help
    Last edited by pari9485; 10-10-2013 at 11:51 AM.

  7. #7
    Registered User
    Join Date
    03-06-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: How to stop the internet explore pop up ?

    I more thing I wanted to ask, If I want to alter this code so that it can take reviews from other websites for eg : http://www.amazon.in/dp/B00CE2LQSW . How can it be done?

  8. #8
    Registered User
    Join Date
    03-06-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: How to stop the internet explore pop up ?

    ..........................................................................................

  9. #9
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: How to stop the internet explore pop up ?

    Hello pai9485,

    I have modified the macro to recognize the URL Amazon India. If present it will extract the review count. Here is the mdified code. The attached workbook contains the change;

    Function GetReviewsCount(ByVal URL As String) As Variant
          
        Dim htmlDoc     As Object
        Dim htmlSpan    As Object
        Dim i           As Long
        Dim metTag      As String
        Dim PageSrc     As String
        
            
            With CreateObject("MSXML2.XMLHTTP")
                .Open "GET", URL, True
                .Send
                                    
                While .readyState <> 4: DoEvents: Wend
                                
              ' Check for any connection errors. Put the error info in cells A4:B4.
                If .statusText <> "OK" Then
                    MsgBox "ERROR " & .Status & " - " & .statusText, vbExclamation, URL
                    Exit Function
                End If
                                
                PageSrc = .ResponseText
            End With
            
            i = InStr(1, PageSrc, "<head>", vbTextCompare)
            If i = 0 Then Exit Function
            
            metaTag = " <meta http-equiv=""X-UA-Compatible"" content=""IE=edge,chrome=1""> "
            PageSrc = Left(PageSrc, i + 5) & metaTag & Right(PageSrc, Len(PageSrc) - i - 5)
    
          ' Create an empty HTML Document and load it with the PageSource.
            Set htmlDoc = CreateObject("htmlfile")
            htmlDoc.Open
            
          ' NOTE: This will check if cookies are enabled and prompt you if they aren't.
            htmlDoc.write PageSrc
          
          ' Close the file for writing.
            htmlDoc.Close
            
            While htmlDoc.readyState <> "complete": DoEvents: Wend
            
                If URL Like "http://www.amazon.in/*" Then
                    Set Div = htmlDoc.getElementById("averageCustomerReviewCount")
                    If Not Div Is Nothing Then
                        GetReviewsCount = Val(Div.ChildNodes(0).ChildNodes(0).NodeValue)
                        Exit Function
                    Else
                        GoTo NoReviews
                    End If
                End If
            
                For Each htmlSpan In htmlDoc.getElementsByTagName("span")
                    If htmlSpan.ClassName = "partner-reviews-count" Then
                        If htmlSpan.NodeType = 1 Then
                            GetReviewsCount = Val(htmlSpan.innerHTML)
                            Exit Function
                        End If
                    End If
                Next htmlSpan
    
    NoReviews:
            GetReviewsCount = "No Review"
            
    End Function
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    03-06-2013
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: How to stop the internet explore pop up ?

    Hi Mr.Ross , Although the code is working for Amazon India, but it is not able to detect some of the pages. Some of the pages having reviews are answered as "No review". I have marked them as yellow.Please have a look.

    Thanks
    Pari
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. code for saving file from Internet Explore
    By aravindhan_31 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-17-2011, 07:06 AM
  2. How to explore the sheets in the workbook
    By MGadAllah in forum Excel General
    Replies: 8
    Last Post: 12-18-2009, 12:01 AM
  3. Windows Explore tree
    By jimbo_jones in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-15-2006, 05:07 PM
  4. Open a non xls file (emulate the double-click from Windows Explore
    By Budget Programmer in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-24-2006, 03:15 PM
  5. Replies: 0
    Last Post: 05-17-2005, 05:49 PM

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