RockandGrohl
Well-known Member
- Joined
- Aug 1, 2018
- Messages
- 788
- Office Version
- 2010
- Platform
- 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.
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.
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
(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:
Lol.. What a mess of a question. Cheers.
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)
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.