+ Reply to Thread
Results 1 to 5 of 5

Error Occurs while running to On Error Goto Line3

Hybrid View

moinsk21 Error Occurs while running to... 06-01-2014, 02:08 PM
mikerickson Re: Error Occurs while... 06-01-2014, 02:22 PM
moinsk21 Re: Error Occurs while... 06-01-2014, 02:29 PM
Norie Re: Error Occurs while... 06-01-2014, 02:30 PM
moinsk21 Re: Error Occurs while... 06-01-2014, 02:37 PM
  1. #1
    Registered User
    Join Date
    03-19-2014
    Location
    India
    MS-Off Ver
    Excel & VBA - 2007 & 2010
    Posts
    60

    Error Occurs while running to On Error Goto Line3

    Hi,

    Someone please advise me, why my Macro is not running the On Error function.

    Example: If on 1st on Error it is going to Line2: then once there is also an error then why it is not going to Line3:
    ????

    I am getting an error : Run-Time Error 75.

    Sub Upload_File()
    
    Dim Old_Path, New_Path, Main_Path As String
        
        Old_Path = Range("V7").Value
        New_Path = Range("V13").Value
        Main_Path = Range("V9").Value
    
    
    On Error GoTo Line1
    Line2:
    Name Old_Path As New_Path
    
    
    MsgBox "File Successfully Uploaded!"
    
    Exit Sub
    
    Line1:
    On Error GoTo Line3
    MkDir Main_Path
    
    GoTo Line2
    
    Line3:
    MsgBox "The file could not be uploaded to SharePoint due to; either Report is already uploaded with the same Name or Allied Error."
    Exit Sub
    End Sub

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Error Occurs while running to On Error Goto Line3

    Try this
    Sub Upload_File()
    
    Dim Old_Path, New_Path, Main_Path As String
        
        Old_Path = Range("V7").Value
        New_Path = Range("V13").Value
        Main_Path = Range("V9").Value
    
    
    On Error GoTo Line1
    Line2:
        Name Old_Path As New_Path
        MsgBox "File Successfully Uploaded!"
    
    Exit Sub
    
    Line1:
        err.Clear
        On Error GoTo Line3
        MkDir Main_Path
        'GoTo Line2
        Resume
    
    Line3:
        err.Clear
        MsgBox "The file could not be uploaded to SharePoint due to; either Report is already uploaded with the same Name or Allied Error."
    Exit Sub
    End Sub
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    03-19-2014
    Location
    India
    MS-Off Ver
    Excel & VBA - 2007 & 2010
    Posts
    60

    Re: Error Occurs while running to On Error Goto Line3

    Thanks! mikerickson.

    actually, i have created a function to identify the file availability.

    below is the new function.

    Sub Upload_File()
    
    Dim Old_Path, New_Path, Main_Path As String
        
        Old_Path = Range("V7").Value
        New_Path = Range("V13").Value
        Main_Path = Range("V9").Value
    
    
    On Error GoTo Line1
    If myFileExists(New_Path) Then
    GoTo Line3
    Else
    End If
    
    Line2:
    
    
    'Name Old_Path As New_Path
    FileCopy Old_Path, New_Path
    
    MsgBox "File Successfully Uploaded!"
    
    Exit Sub
    
    Line1:
    'On Error GoTo Line3
    MkDir Main_Path
    
    GoTo Line2
    
    Line3:
    MsgBox "The file could not be uploaded to SharePoint due to; either Report is already uploaded with the same Name or Allied Error."
    Exit Sub
    End Sub
    Function myFileExists(ByVal strPath As String) As Boolean
    'Function returns true if file exists, false otherwise
        If Dir(strPath) > "" Then
            myFileExists = True
        Else
            myFileExists = False
        End If
    End Function

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

    Re: Error Occurs while running to On Error Goto Line3

    What error(s) are you trying to handle?

    If it's problems with paths/filenames then it might bet better to use Dir rather than On Error.
    If posting code please use code tags, see here.

  5. #5
    Registered User
    Join Date
    03-19-2014
    Location
    India
    MS-Off Ver
    Excel & VBA - 2007 & 2010
    Posts
    60

    Re: Error Occurs while running to On Error Goto Line3

    Thanks Norie,

    I have solved my self only.

+ 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. [SOLVED] Run-time error '9': subscript out of range - error occurs on multiple computers except one
    By BrettE in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-06-2014, 11:19 PM
  2. Error handling for error that occurs frequently
    By adyan76 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-15-2010, 02:50 PM
  3. Error occurs, excel closes when running macro?
    By danny2000 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-27-2008, 06:45 AM
  4. Run-time error '91' when 'On error goto' and cells.find
    By bjoern in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-09-2008, 07:27 PM
  5. [SOLVED] Error Handling - On Error GoTo doesn't trap error successfully
    By David in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-16-2006, 02:10 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