Select multiple files to insert in Excel

evnoort

Board Regular
Joined
Aug 16, 2011
Messages
52
Hi all, I have witten code to insert lines of all txt files in a folder into a excel file.
I used SHBrowseForFolder to select a folder. used code from here: http://j-walk.com/ss/excel/tips/tip29.htm

But I now need to select only a few files from a folder. So a (visual) multiple select.
Any of you got an idea how I can do this. The Folderview control does not seem to do the job.
Do I need to build a user form to do this or is there a better (easyer) way
regards.
 

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,166
try something like this...

<font face=Courier New><SPAN style="color:#00007F">Sub</SPAN> Open_Multi_Files()<br><br>    <SPAN style="color:#00007F">Dim</SPAN> i <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN><br><br>    <SPAN style="color:#007F00">' Prompt user to select a files</SPAN><br>    <SPAN style="color:#00007F">With</SPAN> Application.FileDialog(msoFileDialogOpen)<br>        .InitialFileName = "C:\Temp\"               <SPAN style="color:#007F00">' Default path</SPAN><br>        .FilterIndex = 3<br>        .Title = "Please Select File(s): Ctrl+Click to select multiple files"<br>        .ButtonName = "Open"<br>        .AllowMultiSelect = <SPAN style="color:#00007F">True</SPAN><br>        .Show<br>        <SPAN style="color:#00007F">If</SPAN> .SelectedItems.Count = 0 <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN>   <SPAN style="color:#007F00">' User clicked cancel</SPAN><br>        <SPAN style="color:#00007F">For</SPAN> i = 1 <SPAN style="color:#00007F">To</SPAN> .SelectedItems.Count<br>            <SPAN style="color:#007F00">'Open each selected file</SPAN><br>            Workbooks.Open Filename:=.SelectedItems(i)<br>        <SPAN style="color:#00007F">Next</SPAN> i<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN><br><br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 

Forum statistics

Threads
1,082,342
Messages
5,364,777
Members
400,815
Latest member
gangstar67

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top