+ Reply to Thread
Results 1 to 2 of 2

File Picker

Hybrid View

  1. #1
    Registered User
    Join Date
    01-14-2014
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    14

    File Picker

    Hi all,

    Hope you are well and patient enough to go through this with me.

    I am trying to create a multiple file picker. The code is below.

    I want to open the first file of lets say 5 selected files, do some autofilter task, copy data from that file, paste it in another workbook and close it. Open second file, do some autofilter task, copy data from that file, paste it in below the first file pasted data in another workbook and close it... and File 3... and so on.

    It works for one file, the code for copying pasting is not yet added. I think I can manage that. But how I return to the fileicker function after it opens the first file.


    Private Sub Merge_Data_Click()
    
    Dim csvWbkPath As String
    
    csvWbkPath = FilePickerCSV()
        
        If csvWbkPath = "Exit" Then
            Sheets("Macro").Select
            Exit Sub
            ElseIf csvWbkPath = "" Then
                MsgBox ("Aborting the process!")
                Worksheets("Macro").Select
                Range("A2").Select
                Exit Sub
        End If
        
        csvWbkName = Right(csvWbkPath, Len(csvWbkPath) - InStrRev(csvWbkPath, "\"))
        Workbooks.Open (csvWbkPath)
    
    
    
    End Sub
    
    Function FilePickerCSV(Optional initialPath As String = "", Optional title As String = "Please select a file", Optional filters As String = "")
    
      Dim fDialog As Office.FileDialog
      Dim selectedFile As String
      Dim filter, filterName, filterExtn
      Dim i As Integer
      
      MSG1 = MsgBox("Please select the CSV file.", vbYesNo)
      
      If MSG1 = vbYes Then
      
        Set fDialog = Application.FileDialog(msoFileDialogFilePicker)
        
        With fDialog
          If initialPath > "" Then
            .InitialFileName = initialPath
          End If
          
          .AllowMultiSelect = True
          .title = title
          .filters.Clear
          .InitialFileName = "" 'clear the file box
          
          If filters > "" Then
            For Each filter In Split(filters, "|")
              If filter > "" Then
                i = InStr(filter, ",")
                filterName = Left(filter, i - 1)
                filterExtn = Mid(filter, i + 1)
                .filters.Add filterName, filterExtn
              End If
            Next
          Else
            .filters.Add "All files", "*.CSV"
          End If
          
          Dim fl As Integer
          
          If .Show = True Then
            'selectedFile = .SelectedItems(5)
            'open each of the files chosen
          For fl = 1 To .SelectedItems.Count
    
    THIS IS WHERE I AM OPENING THE SELECTED FILE. i WANT TO RETURN TO THE MAIN FUNCTION AND DO COPY/PASTE/CLOSE AND COME HERE AGAIN TO GO THROUGH THE SECOND FILE.
    
            Workbooks.Open .SelectedItems(fl)
            selectedFile = .SelectedItems(fl)
            FilePickerCSV = selectedFile
          Next fl
          
          End If
        End With
        
        FilePickerCSV = selectedFile
        Else
        FilePickerCSV = "Exit"
        
        End If
    
    End Function
    Many thanks,
    rajwar
    Last edited by rajwar; 03-06-2014 at 11:31 AM.

  2. #2
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    328

    Re: File Picker

    put "PlaceMarker:" where you want the macro to return to and ask for another file and at the end of the macro before the last end if put "Goto PlaceMarker".

    you could also start with a "Do While True" and end with a "Loop" and have
    If MSG1 = VbNo Then Exit Do
    Last edited by Leon V (AW); 03-06-2014 at 11:51 AM.
    Sub Reputation()
    Dim Problem as Variant
    Dim Reputation as Integer
    For Each Problem in Forum.Threads
        If Problem.Title = "*[Solved]*" and Solver.Name = "Leon V (AW)" Then Reputation = Reputation + 1
    Next Problem
    End Sub

+ 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. Replies: 4
    Last Post: 04-19-2021, 06:44 AM
  2. code won't display a selected image from a file picker, in a user form Any ideas?
    By jakeembx in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 01-09-2014, 02:47 PM
  3. File dialog list picker
    By julhs in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-01-2013, 12:42 PM
  4. File picker in excel 2007
    By irfanparbatani in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 11-14-2012, 12:01 AM
  5. File Picker problem
    By noodle48 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-01-2011, 11:49 PM

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