+ Reply to Thread
Results 1 to 5 of 5

On error goto

Hybrid View

  1. #1
    Registered User
    Join Date
    01-19-2010
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    3

    On error goto

    Hi,

    I am trying to create a macro that runs a path if it is present, if not it will try the next down down in a list, and so on until it shows an error message if nothing is found. An extract of the code is beneath, but the second on error goto wont work, it just says "File not found" and stops. However the first one works just fine. I am sure that there is a far cleaner way of doing this, but I'm darned if I know it. Any help would be greatly appreciated as I have been mucking about with it for hours.


    Private Sub runTxShuttleScript(scriptName As String, xlFile As String, sheetName As String, startRow As String, numRows As String, Optional logColumn As String)
    
            On Error GoTo newshuttle
            programm = "c:\program files\winshuttle\txshuttle\txshuttle.exe"
            out = Shell(programm & " " & scriptName & xlFile & sheetName & startRow & numRows & logColumn, vbNormalFocus)
    
    exithandler:
            Exit Sub
            
    newshuttle:
           On Error GoTo newshuttle2
           programm = "C:\Program Files\Winshuttle\transactionSHUTTLE8\txshuttle.exe"
           out = Shell(programm & " " & scriptName & xlFile & sheetName & startRow & numRows & logColumn, vbNormalFocus)
            
    exithandler2:
            Exit Sub
    
    newshuttle2:
            On Error GoTo errhandler
            programm = "c:\program files\winshuttle\runshuttle8\txrunner.exe"
            out = Shell(programm & " " & scriptName & xlFile & sheetName & startRow & numRows & logColumn, vbNormalFocus)
            
    exithandler3:
            Exit Sub
    
    
    errhandler:
            MsgBox "This operation can only be run on a computer with XXXXX." & vbNewLine & "You do not have the correct software.", _
            vbOKOnly, "No Software Found"
            Sheets("Master").Select
            
    End Sub
    Last edited by tostle; 01-19-2010 at 01:19 PM. Reason: add code tags

  2. #2
    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 goto problem

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here

    Code tags added this time
    Hope that helps.

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

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    01-19-2010
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: On error goto problem

    Thanks RoyUK

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

    Re: On error goto

    Maybe like this?
    Private Sub runTxShuttleScript(scriptName As String, xlFile As String, sheetName As String, startRow As String, numRows As String, Optional logColumn As String)
        On Error Resume Next
    
        programm = "c:\program files\winshuttle\txshuttle\txshuttle.exe"
        out = Shell(programm & " " & scriptName & xlFile & sheetName & startRow & numRows & logColumn, vbNormalFocus)
        If Err.Number = 0 Then Exit Sub
    
        programm = "C:\Program Files\Winshuttle\transactionSHUTTLE8\txshuttle.exe"
        out = Shell(programm & " " & scriptName & xlFile & sheetName & startRow & numRows & logColumn, vbNormalFocus)
        If Err.Number = 0 Then Exit Sub
    
        programm = "c:\program files\winshuttle\runshuttle8\txrunner.exe"
        out = Shell(programm & " " & scriptName & xlFile & sheetName & startRow & numRows & logColumn, vbNormalFocus)
        If Err.Number = 0 Then Exit Sub
    
        MsgBox "This operation can only be run on a computer with XXXXX." & vbNewLine & "You do not have the correct software.", _
               vbOKOnly, "No Software Found"
        Sheets("Master").Select
    End Sub
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Registered User
    Join Date
    01-19-2010
    Location
    London, England
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: On error goto

    Brilliant, thanks shg, works a charm.

+ 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