+ Reply to Thread
Results 1 to 4 of 4

on error doesn't work

Hybrid View

  1. #1
    Registered User
    Join Date
    03-16-2009
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    64

    on error doesn't work

    when i disable internet connection to try the error procedure instead of doing the line related to the error the macro show a message error ; can someone tell where the error is thanks .i've added 2 attachments too to see what happens when i push F8.

    
    Workbooks.Add.Activate
    ActiveWorkbook.SaveAs Filename:="C:\documenti1\documenti2\FONDI1\downloaded_etf"
    Sheets("Foglio1").Activate
    Sheets("Foglio1").Name = "dati etf"
            With ActiveSheet.QueryTables.Add(Connection:= _
            "URL;http://www.borsaitaliana.it/bitApp/listino?service=Data&lang=it&main_list=11&sub_list=2" _
            , Destination:=ActiveCell)
            .Name = "listino?service=Data&lang=it&main_list=11&sub_list=2"
            .FieldNames = True
            .RowNumbers = False
           .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .WebSelectionType = xlSpecifiedTables
            .WebFormatting = xlWebFormattingNone
            .WebTables = "6,7,8"
            .WebPreFormattedTextToColumns = True
            .WebConsecutiveDelimitersAsOne = True
            .WebSingleBlockTextImport = False
            .WebDisableDateRecognition = False
            .WebDisableRedirections = False
            
    Etichetta1:
            
            .Refresh BackgroundQuery:=False
            
            'On Error Resume Next
            On Error GoTo Etichetta
    
           
           
           
        End With
    Attached Images Attached Images

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: on error doesn't work

    Error handling should be structured like this:
    Sub Test()
        ' code that should not error
        
        On Error GoTo Oops
        '
        ' code that may raise an error
        '
        On Error GoTo 0
        
        ' code that should not error
    
    Outtahere:
        Exit Sub ' to avoid error handler
        
    Oops:
        ' code to handle error
        
        Resume Next     ' to resume where you left off
        Resume Outtahere  ' or this, to go to the normal exit
    End Sub
    Last edited by shg; 05-20-2009 at 09:56 PM.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    03-16-2009
    Location
    italy
    MS-Off Ver
    Excel 2003
    Posts
    64

    Re: on error doesn't work

    thank for your help ; but there is still some problem when there is no connection it enter Etichetta1:
    and give me the same error ; with connection evrything is ok
    Sub IN_LAVORAZIONE()
           Dim cont As Byte
    
    
           
            With ActiveSheet.QueryTables.Add(Connection:= _
            "URL;http://www.borsaitaliana.it/bitApp/listino?service=Data&lang=it&main_list=11&sub_list=2" _
            , Destination:=ActiveCell)
            .Name = "listino?service=Data&lang=it&main_list=11&sub_list=2"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .WebSelectionType = xlSpecifiedTables
            .WebFormatting = xlWebFormattingNone
            .WebTables = "6,7,8"
            .WebPreFormattedTextToColumns = True
            .WebConsecutiveDelimitersAsOne = True
            .WebSingleBlockTextImport = False
            .WebDisableDateRecognition = False
            .WebDisableRedirections = False
    Etichetta1:
            On Error GoTo Etichetta
            .Refresh BackgroundQuery:=False
            On Error GoTo 0
            End With
           
     
            
            Exit Sub
    Etichetta:
           CreateObject("WScript.Shell").Popup "nuovo tentativo: " & cont & " di 60    tra 5 secondi", 1, "errore nello scaricare i dati"
           Sleep 5000
           cont = cont + 1
           If cont = 60 Then
           MsgBox "PROBLEMA SULLA RETE INTERNET impossibile scaricare i dati"
           End If
        
           GoTo Etichetta1
            
            
            
         
       End Sub

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: on error doesn't work

    You still have the On Error in the wron place, it should be before the code starts
    Option Explicit
    
    Sub IN_LAVORAZIONE()
        Dim cont   As Byte
    
        On Error GoTo Etichetta
    
        With ActiveSheet.QueryTables.Add(Connection:= _
                                         "URL;http://www.borsaitaliana.it/bitApp/listino?service=Data&lang=it&main_list=11&sub_list=2" _
                                         , Destination:=ActiveCell)
            .Name = "listino?service=Data&lang=it&main_list=11&sub_list=2"
            .FieldNames = True
            .RowNumbers = False
            .FillAdjacentFormulas = False
            .PreserveFormatting = True
            .RefreshOnFileOpen = False
            .BackgroundQuery = True
            .RefreshStyle = xlInsertDeleteCells
            .SavePassword = False
            .SaveData = True
            .AdjustColumnWidth = True
            .RefreshPeriod = 0
            .WebSelectionType = xlSpecifiedTables
            .WebFormatting = xlWebFormattingNone
            .WebTables = "6,7,8"
            .WebPreFormattedTextToColumns = True
            .WebConsecutiveDelimitersAsOne = True
            .WebSingleBlockTextImport = False
            .WebDisableDateRecognition = False
            .WebDisableRedirections = False
    Etichetta1:
            .Refresh BackgroundQuery:=False
        End With
    
        On Error GoTo 0
    
        Exit Sub
    Etichetta:
        CreateObject("WScript.Shell").Popup "nuovo tentativo: " & cont & " di 60    tra 5 secondi", 1, "errore nello scaricare i dati"
        Sleep 5000
        cont = cont + 1
        If cont = 60 Then
            MsgBox "PROBLEMA SULLA RETE INTERNET impossibile scaricare i dati"
        End If
    
        GoTo Etichetta1
    
    
    End Sub
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ Reply to Thread

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