Results 1 to 5 of 5

Detect if user hits cancel from user input type box

Threaded View

welchs101 Detect if user hits cancel... 10-17-2011, 02:39 PM
arlu1201 Re: Detect if user hits... 10-17-2011, 02:42 PM
welchs101 Re: Detect if user hits... 10-17-2011, 02:43 PM
arlu1201 Re: Detect if user hits... 10-20-2011, 11:15 AM
romperstomper Re: Detect if user hits... 10-20-2011, 11:42 AM
  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,712

    Detect if user hits cancel from user input type box

    I have the following code which gets all the files in a director. The problem is if a user hits cancel then it exits the subroutine but my subsequent code does not know that cancel was hit.

    Any ideas on how to identify if cancel was hit...........


    '***********************************************************************
    '***********************************************************************
    '     Procedure obtained from LeithRoss at "Excel Forum"
    '     http://www.excelforum.com/excel-programming/776444-reading-in-the-
    '     files-in-a-directory-into-an-array-directory-chosen-by-user.html
    '
    '***********************************************************************
    '***********************************************************************
    Sub get_list_of_files_and_path(file_array() As Variant, Path1 As String)
    
    Dim Cnt As Long
    Dim ExcelFiles() As Variant
    Dim FilePath As String
    Dim FileName As String
    Dim objShell As Object
        
        Set objShell = CreateObject("Shell.Application")
        
        Set oFolder = objShell.BrowseForFolder(0, "Pick a Folder to Open", 0)
        If oFolder Is Nothing Then Exit Sub
        
          FilePath = oFolder.Self.Path & "\"
          
          'MsgBox (FilePath)
          Path1 = FilePath
          
          'FileName = Dir(FilePath & "*.xls")
            FileName = Dir(FilePath & "*.*")
    
          If FileName = "" Then
             MsgBox "No Excel Files were Found in this Folder.", vbCritical
             Exit Sub
          End If
          
    
          Cnt = 1
            Do While FileName <> ""
              ReDim Preserve ExcelFiles(Cnt)
              ReDim Preserve file_array(Cnt)
              ExcelFiles(Cnt) = FilePath & FileName
              file_array(Cnt) = FileName
              'MsgBox (FileName)
              Cnt = Cnt + 1
              FileName = Dir()
            Loop
        
        
    
    End Sub
    Last edited by welchs101; 10-21-2011 at 07:36 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