Results 1 to 9 of 9

Ending macro early

Threaded View

  1. #1
    Registered User
    Join Date
    11-26-2008
    Location
    New England
    MS-Off Ver
    2007
    Posts
    35

    Ending macro early

    I need to step out of a macro based on a user respone, and I don't know how to end this macro if the user needs to correct a cell entry.

    If they respond "no", I want to sub to end and select the cell where the correction needs to be made.

    Thanks
    Ted

    If Dir(filePath, vbDirectory) = vbNullString Then
            Dim FolderMsg, ResponseFolder
            FolderMsg = "This folder does not exist." & Chr(13) & Chr(13) _
               & "Do you want to create a new customer folder?"
           ResponseFolder = MsgBox(FolderMsg, vbYesNo + vbInformation)
    If ResponseFolder = vbYes Then
                 MkDir filePath
    End If
    If ResponseClose = vbNo Then
                Dim CustMsg, ResponseCustMsg As String
                CustMsg = "Check the customer name." & Chr(13) & Chr(13) _
                & "Correct if needed."
                ResponseCustMsg = MsgBox(CustMsg, vbOKOnly + vbCritical)
                Range("I5").Select
                Exit Sub  'THIS IS WHERE I NEED TO EXIT THE MACRO
    End If
    
    End If
        Rem
        Rem http://www.excelforum.com/excel-programming/663085-save-as-and-creating-directory.html
        Rem
        Rem Save the file in the proper folder
    If ActiveWorkbook.FullName = filePath & Application.PathSeparator & namePN & " PrtRev_ " _
                             & nameRev & " SO_" & nameSO & " ILRev2.xls" Then
        Dim DuplicateMsg, ResponseDuplicate
        DuplicateMsg = "This file already exists." & Chr(13) & Chr(13) _
            & "Do you want to overwrite it?"
        ResponseDuplicate = MsgBox(DuplicateMsg, vbYesNo + vbInformation)
    If ResponseDuplicate = vbYes Then
        ActiveWorkbook.Save
            
    End If
    Else
    ActiveWorkbook.SaveAs filePath & Application.PathSeparator & namePN & " PrtRev_ " _
                             & nameRev & " SO_" & nameSO & " ILRev2.xls"
    Range("e1") = "serenity now!"
    End If
        Rem
        ActiveWindow.WindowState = xlMaximized
        Calculate
        Range("F13").Select
        Rem ActiveWorkbook.Close
        
        Rem End of loop should go here
        
        Rem Dim CloseMsg, ResponseClose
        Rem PrintMsg = "Do you want to close the file?" & Chr(13)
           Rem ResponseClose = MsgBox(PrintMsg, vbYesNo + vbInformation)
        Rem If ResponseClose = vbYes Then
        Rem ActiveWorkbook.Close True
        Rem End If
    
    Else
        Dim WrongMsg As String
        WrongMsg = "This may not be an Inspectional Layout file." & Chr(13) & Chr(13) _
        & "This macro will not run on files that are not this type."
        MsgBox WrongMsg, vbOKOnly + vbCritical
       
    End If
    '
    
    End Sub
    Last edited by TedH; 01-20-2009 at 11:42 AM.

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