+ Reply to Thread
Results 1 to 8 of 8

object invoked error causing excel to crash

Hybrid View

edopts object invoked error causing... 07-14-2014, 04:00 PM
TMS Re: object invoked error... 07-14-2014, 04:39 PM
edopts Re: object invoked error... 07-14-2014, 05:22 PM
TMS Re: object invoked error... 07-14-2014, 05:39 PM
edopts Re: object invoked error... 07-18-2014, 08:26 AM
TMS Re: object invoked error... 07-18-2014, 10:36 AM
edopts Re: object invoked error... 09-11-2014, 12:49 PM
TMS Re: object invoked error... 09-11-2014, 12:55 PM
  1. #1
    Registered User
    Join Date
    06-13-2014
    Posts
    23

    object invoked error causing excel to crash

    I am receiving the following error:

    -2147417848 automation error the object invoked has disconnected from its clients

    Unfortunately, I can't tell where the error is occurring because everytime it happens excel crashes or at least stops responding. I tried waiting it out (about 20 minutes) but no luck. the only thing I can do is force the program to shut down through the task manager.

    The program is designed to pull information from finviz.com (a financial site), filter the data. pull the next round of data and run the filters again. there are a total of 8 queries and i think it gets hung up during the 6th or 7th run through.

    Stepping through the code does not seem practical since each query might pull as many as 300 rows of data that is evaluated in a for/next loop (thats a lot of F8s).

    I am not really sure what to do at this point. Is there some other way to debug this?

    Thanks in advance and please let me know if i can provide additional information.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,494

    Re: object invoked error causing excel to crash

    No workbook, no data, no code. How would you have us diagnose the fault?

    You are, presumably, looping through a list. So put a Stop in place at the start of the loop. Press F5 and see if the first iteration works. If it does, repeat he process until it fails.

    Alternatively, if the list is on a worksheet, remove all the entries but one. Test it. If it works, replace it with the next and test it. Repeat until it fails.

    Hopefully, that will determine which of the sites causes the failure/loop/lock-up/whatever.

    If all the sites work, it must be something to do with the processing of the data.

    Not a lot to add with no information.

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    06-13-2014
    Posts
    23

    Re: object invoked error causing excel to crash

    I have included the code below, but this is more a debugging technique question. The code works fine when either of the individual filters are run, i.e. I remove one of the filters for testing. My intention is to add two more filters.
    Note: at the end of the code I have the application wait 5 seconds before going to the next query. this was an experiment and actually allowed it to run to the 7th query. prior to adding that line it was getting hung up on the 4th.

    
    Sub GetFinvizData()
    
    Dim RowCt As Integer
    Dim RowTot As Variant, RowTotSub As Variant
    Dim Z As Integer, Y As Integer, x As Integer
    Dim strFinSite As String
    Dim strFin(1 To 8) As String
        strFin(1) = "basicmaterials"
        strFin(2) = "consumergoods"
        strFin(3) = "financial"
        strFin(4) = "healthcare"
        strFin(5) = "industrialgoods"
        strFin(6) = "services"
        strFin(7) = "technology"
        strFin(8) = "utilities"
    
    
    For Y = 1 To 8
        Sheets(strFin(Y)).Activate
        Range("A2", "K2").Select
        Range(Selection, Selection.End(xlDown)).Select
        Selection.ClearContents
        Selection.ClearFormats
    Next Y
    
    For Z = 1 To 8
    
    Sheets("Raw").Activate
    Range("A1").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.ClearContents
    
    'Download Stock Data
    
    strFinSite = "http://finviz.com/export.ashx?v=151&f=ind_stocksonly,sec_" & strFin(Z) & ",sh_avgvol_o500,sh_opt_optionshort,sh_price_o10&ft=4&o=industry&c=1,2,4,42,43,44,45,46,47,65,68"
    QueryQuote:
                With Sheets("Raw").QueryTables.Add(Connection:="URL;" & strFinSite, Destination:=Sheets("Raw").Range("a1"))
                    .BackgroundQuery = True
                    .TablesOnlyFromHTML = False
                    .Refresh BackgroundQuery:=False
                    .SaveData = True
                End With
    
    Sheets("Raw").Range("a1").CurrentRegion.TextToColumns Destination:=Sheets("Raw").Range("a1"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
    Semicolon:=False, Comma:=True, Space:=False, other:=True, OtherChar:=",", FieldInfo:=Array(1, 2)
           
    Sheets("Raw").Columns("A:B").ColumnWidth = 12
    Range("A1").Select
    
    'Filters bullish reversing trades based on:
        '-Week and month performance positive
        '-Half performance negative
       
    Sheets("Raw").Activate
    RowTot = ActiveSheet.UsedRange.Rows.Count
    
    For RowCt = 2 To RowTot
        If (Sheets("Raw").Cells(RowCt, 7).Value < 0 And Sheets("Raw").Cells(RowCt, 5).Value > 0 And _
                Sheets("Raw").Cells(RowCt, 4).Value > 0) Then
                    Range("A" & RowCt & ":" & "K" & RowCt).Select
            Selection.Copy Destination:=Sheets(strFin(Z)).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
        End If
    Next RowCt
    
    Sheets(strFin(Z)).Activate
    RowTotSub = ActiveSheet.UsedRange.Rows.Count
    x = 1
    
    Do Until x > RowTot
                If Cells(x, 1).Interior.TintAndShade = 0 And Cells(x + 1, 1).Value = 0 Then
                Cells(x, 1).Select
                Range(Selection, Cells(x, 11)).Select
                    Exit Do
                ElseIf Cells(x, 1).Interior.TintAndShade = 0 And Cells(x, 1).Value <> 0 Then
                    Cells(x, 1).Select
                    Range(Selection, Cells(x, 11)).Select
                    Range(Selection, Selection.End(xlDown)).Select
                Exit Do
            
            End If
        
        x = x + 1
        
    Loop
    
        With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorAccent6
            .TintAndShade = 0.799981688894314
            .PatternTintAndShade = 0
        End With
    
    'Filters bullish continuation trades based on:
        '-Month, quarter, & half performance positive
        '-Week performance negative
     
    Sheets("Raw").Activate
    RowTot = ActiveSheet.UsedRange.Rows.Count
    
    For RowCt = 2 To RowTot
        If (Sheets("Raw").Cells(RowCt, 4).Value < 0 And Sheets("Raw").Cells(RowCt, 5).Value > 0 And _
                Sheets("Raw").Cells(RowCt, 6).Value > 0 And Sheets("Raw").Cells(RowCt, 7).Value > 0) Then
                    Range("A" & RowCt & ":" & "K" & RowCt).Select
            Selection.Copy Destination:=Sheets(strFin(Z)).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
        End If
    Next RowCt
    
    Sheets(strFin(Z)).Activate
    RowTotSub = ActiveSheet.UsedRange.Rows.Count
    x = 1
    
    Do Until x > RowTot
                If Cells(x, 1).Interior.TintAndShade = 0 And Cells(x + 1, 1).Value = 0 Then
                Cells(x, 1).Select
                Range(Selection, Cells(x, 11)).Select
                    Exit Do
                ElseIf Cells(x, 1).Interior.TintAndShade = 0 And Cells(x, 1).Value <> 0 Then
                    Cells(x, 1).Select
                    Range(Selection, Cells(x, 11)).Select
                    Range(Selection, Selection.End(xlDown)).Select
                Exit Do
            
            End If
        
        x = x + 1
        
    Loop
        With Selection.Interior
            .Pattern = xlSolid
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorAccent1
            .TintAndShade = 0.799981688894314
            .PatternTintAndShade = 0
        End With
        
    Application.Wait (Now + TimeValue("0:00:05"))
    
    Next Z
    
    End Sub

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,494

    Re: object invoked error causing excel to crash

    OK, well I've offered some suggestions about diagnosing the problem (using Stop, primarily, and stepping through the code.)

    Be aware that UsedRange is fickle and it's better to use a specific fully populated column to determine the last row.

    Also, it's sometimes a good idea to have a "get out of jail" card in a Do Loop where you are testing a condition. If the condition isn't met, for some reason, you might not be able to exit the loop. So, maybe put an arbitrary large counter in and exit if that counter is exceeded.

    I would also advise consistent indenting of code within loops and If blocks etc; makes it easier to see what is linked together, for example, what happens before an Exit Do.

    Regards, TMS

  5. #5
    Registered User
    Join Date
    06-13-2014
    Posts
    23

    Re: object invoked error causing excel to crash

    Hi TMS,
    The Stop idea was helpful particularly since there are so many loops. I placed a few of them through out the code and was able to identify the error. As it turned out, it was UsedRange that was producing a extremely large number when Z = 7. No idea why it only happened on 7, but using column A which was always fully populated solved that.
    Unfortunately, it still crashes when I try to run the entire code. However, if I put a Stop in before it goes to the next Z and hit F5 it will make it all the way through without crashing. That has me stumped. I wouldn't care that much if I were the only one who was going to use it, but my intention was to share it with a few people. Any thoughts?
    Thanks.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,494

    Re: object invoked error causing excel to crash

    Well, when you use Stop to halt and step through the code, Evan allowing big chunks to process, you are giving it "thinking time" which sort of implies it' sample timing issue. Speeding up your code may be a good thing or a bad thing, but you probably need to try it. Instead of copying the rows individually, you should build up a range of cells to be copied. If you are copying whole rows, you only need to store a representative cell and then extend the range to EntireRow at the end.

    Where you are looping down column A at the end, instead of selecting the cells in a row or rows, assign them to a range variable and then use that range variable to apply the formatting.

    Basically, you don't want to be selecting anything, either to copy it or format it.

    Once you have made your code as efficient as possible, you can experiment with the delay that you apply at the end of the loop.


    Regards, TMS

  7. #7
    Registered User
    Join Date
    06-13-2014
    Posts
    23

    Re: object invoked error causing excel to crash

    Hi TMS,
    I took your advice and experimented with some ways to eliminate the individual line copies. Ended up using the Union method which works perfectly and is extremely quick. Thanks again for your help.
    Best,
    edopts

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,494

    Re: object invoked error causing excel to crash

    You're welcome.

+ 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. automation error the object invoked -2147417848
    By Proteo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-04-2014, 08:57 AM
  2. [SOLVED] Error: automation error the object invoked has disconnected from its clients
    By siroos12 in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 12-24-2013, 08:56 AM
  3. Replies: 7
    Last Post: 05-15-2013, 09:02 AM
  4. Error:The object invoked has disconnected from client.
    By gpnavin in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-28-2012, 01:09 PM
  5. Replies: 7
    Last Post: 01-15-2010, 02:34 PM

Tags for this Thread

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