Select multiple files to open, then later open them

RockandGrohl

Active Member
Joined
Aug 1, 2018
Messages
497
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.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
52,758
Office Version
  1. 365
Platform
  1. Windows
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.
 

Some videos you may like

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

RockandGrohl

Active Member
Joined
Aug 1, 2018
Messages
497
Office Version
  1. 2010
Platform
  1. Windows
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,122,246
Messages
5,595,044
Members
413,963
Latest member
teggl97

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
Top