variable source folder for import

little_alien

New Member
Joined
Nov 21, 2017
Messages
1
Morning,

looking for some help with importing CSV files but with a variable source folder -

I need to have a Button(VBA) that opens and allows the user to select a source folder,
after which it will import the CSV files within.

I have the Query's for appending the files already but the source folder has always been hard coded.

Cheers
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi, welcome to the board.
How about
Code:
Sub OpenFldr()

    Dim FldrPth As String
    Dim InitPth As String
    Dim FName As String
    Dim Fldr As Object
    
    InitPth = "[COLOR=#ff0000]C:\Users\Fluff\Documents[/COLOR]"
    
    Set Fldr = Application.FileDialog(4)
    With Fldr
        .Title = "Select a Folder"
        .AllowMultiSelect = False
        .InitialFileName = InitPth
        If .Show <> -1 Then Exit Sub
        FldrPth = .SelectedItems(1)
    End With
    
    FldrPth = FldrPth & "\"
    FName = Dir(FldrPth & "*.csv")
    Do While Len(FName) > 0
        Workbooks.Open (FldrPth & FName)
        'Your code here
        FName = Dir
    Loop

End Sub
Change the path in red to the path you want to start in
 
Upvote 0

Forum statistics

Threads
1,214,568
Messages
6,120,272
Members
448,953
Latest member
Dutchie_1

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