Select multiple files to open, then later open them

RockandGrohl

Well-known Member
Joined
Aug 1, 2018
Messages
788
Office Version
  1. 2010
Platform
  1. Windows
Hi all, I have this code within a userform called CPanel.

You press a button and navigate to one of a few folders that contain reports in. You can select one or multiple files. Upon selection, the filenames for the reports are written in a text-box with a carriage return in between them, to allow the user to review the files chosen, see below.

VBA Code:
Dim fd As FileDialog
Dim oFD As Variant
Dim fileName As String

    Set fd = Application.FileDialog(msoFileDialogFilePicker)
    With fd
        .ButtonName = "Select"
        .AllowMultiSelect = True
        .InitialFileName = "\\chw-dc03\company\Sales"
        .Filters.Add "Excel Files", "*.xls*", 1
        .Title = "Please choose a DM Report to open"
        .InitialView = msoFileDialogViewDetails
        .Show
        
        For Each oFD In .SelectedItems
            fileName = oFD
           
            'CampList.Text = CampList.Text & Mid(fileName, InStrRev(fileName, "\") + 1) & vbCrLf
            CampList.Text = fileName & vbCrLf
        Next oFD
        On Error GoTo 0
    End With
       
    Set fd = Nothing


Once the user is satisfied with the files selected, they press a button to open each sheet in turn and import the data into the main sheet "Import"

This is where I'm getting stuck. My list of files will be something like this, with only the filenames shown.

1. Big Report 21-02-2020.xlsx
2. Coach report 04-05-2020.xlsx
3. Christmas report 11-11-2020.xlsx

Should I preface each opening with a variable string pName (pathname) that ideally would be chosen for where the files are opened, right? Like below
VBA Code:
pName = Left(fileName, InStr(fileName, "\") + 1)
(Obviously I'd jiggle the +1 depending on what gets spat out at me)

So I need to loop through the reports, open the first one, do the data shenanigans (I should be ok writing this code) and then close the workbook and find the next filename in the list. This is where I'm getting stuck, because I don't know how to split one or more strings by the carriage return? I essentially want to write something like:

VBA Code:
Do until list of all workbooks is exhausted
Set wb = workbooks.open(pName & [somehow determined first file name])
'doing all my copy-pasting stuff here
Wb.close 
Loop


Lol.. What a mess of a question. Cheers.
 
That does make sense, in which case you need to store the path somewhere so that you can use it later.
Whilst I put it in a textbox, there other ways to do it.
 
Upvote 0

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Oh my God ignore me, sorry didn't see what you were doing with the text box, thought you were duplicating. Yes I believe this is working wonderfully :) I'll make the Textbox small and pop the path in it.
 
Upvote 0

Forum statistics

Threads
1,214,666
Messages
6,120,806
Members
448,990
Latest member
rohitsomani

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top