Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 21st, 2010, 04:31 PM
Registered User
 
Join Date: Jan 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Excel vba looping with Internet Explorer freezing machine

Hi all. I've looked high and low for a solution to this issue but to no avail. Just when I thought I had it tested on a few sample parameters, it freezes up when I put it to the test of real data. In a nutshell, I'm using internet explorer (my first time doing this method, have been using web queries) to parse data out of html data tables. Seems pretty straightforward. I pass the sub a web address string. I need to loop it several thousand times, though. After it runs a few times, my machine freezes up. Sometimes I get an "out of memory" error, sometimes not. In all cases I can't open any other files, and I get the "thud" sound when clicking on just about anything, even ctl alt del. I'm disposing of the IE instances at the end of every run, so, any help? Here's the code:

Code:
Sub OptionsDataDownload(str As String)
'Uses instances of IE to parse web tables.
Dim objIE As Object
Dim varTables, varTable
Dim varRows, varRow
Dim varCells, varCell
Dim lngRow As Long, lngColumn As Long
Dim myTime As Date
Dim sPage As String
Dim WSUsedRow As Long
    Set WS = Worksheets("Workspace")
    WS.Cells.Clear
    
    'Create a new hidden instance of IE.
    Set objIE = New SHDocVw.InternetExplorer
    objIE.Visible = True
    
    'Open the web page.
    objIE.Navigate str
    
    'Set the timer for the page download.
    Let myTime = Now
    Do While (Now - myTime) < TimeSerial(0, 0, 7)
        If objIE.ReadyState = READYSTATE_COMPLETE Then
            Exit Do 'Don't hold if not necesary
        End If
    Loop
    
    If objIE.ReadyState <> READYSTATE_COMPLETE Then
        GoTo Cleanup 'Timed out, exit.
    End If
    'See if there are options for this date.
    sPage = objIE.Document.body.innerText
    If InStr(sPage, "No options are available for this date.") Then
        Exit Sub
    End If
    Set varTables = objIE.Document.All.tags("TABLE")
    
    WSUsedRow = 1
    For Each varTable In varTables
    
      'Use the innerText to see if this is the table we want.
      If InStr(varTable.innerText, "Strike PriceSymbolLastChg%ChgTime ValueBidAskVolOpen Interest") _
        And InStr(varTable.innerText, "Options for ") = False Then
        
        'If so, parse the web tables.
        Set varRows = varTable.Rows
        For Each varRow In varRows
          Set varCells = varRow.Cells
          lngColumn = 1 'This will be the output column
          For Each varCell In varCells
            WS.Cells(WSUsedRow, lngColumn) = varCell.innerText
            lngColumn = lngColumn + 1
          Next varCell
          WSUsedRow = WSUsedRow + 1
        Next varRow
        
      End If
    Next varTable
    
Cleanup:
  Set varCell = Nothing: Set varCells = Nothing
  Set varRow = Nothing: Set varRows = Nothing
  Set varTable = Nothing: Set varTables = Nothing
  objIE.Quit
  Set objIE = Nothing
End Sub
 
Old January 23rd, 2010, 04:45 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

This is not quite strange, There are multiple reasons why the IE/App hangs. There is a possiblity that the App takes quite sometime to navigate to the site ... some messages, popups, activeX control that doesn;t allow your site to complete the navigation etc

You can get to a solution of you find the exact reason for the hang
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips &amp; Tricks (http://www.vbadud.blogspot.com)
 
Old January 24th, 2010, 09:37 AM
Registered User
 
Join Date: Jan 2010
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Thanks...

Thanks for the response. So you think it's IE hanging up? That's what I don't understand. When I go to the pages that I pass as the string for the page address, they're "clean" and fast, no frills, no popups etc. That's what I'm asking, what the hang could be.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Internet Explorer cannot open the internet site cathiec ASP.NET 2.0 Basics 1 October 22nd, 2005 01:30 PM
Internet Explorer JelfMaria VB How-To 10 April 27th, 2005 03:58 PM
Access Internet Explorer via Excel VBA tony_813 Excel VBA 2 March 6th, 2005 08:20 PM
vba and internet explorer ken1978 VB How-To 0 January 23rd, 2005 09:11 PM
Run VBA Excel File On Internet Explorer DHDang Excel VBA 0 November 12th, 2003 03:39 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.