Using macros to open any .csv files from specifed directory

ClarkE

New Member
Joined
Sep 2, 2002
Messages
13
Greetings!

Is it possible to write a macro that will look into a specific directory and open any .csv files that exist in it? The filenames could change from one day to the next. The directory may even be empty! Can it loop until all files processed or do I have to keep running the macro? Having asked all thi, what is the macro?

I have been asked if it is possible to build a 'master' workbook that opens such files, copies the data (standardized) into an 'assembler' workbook, in which some formulae will assemble various scripts and scenarios; the macro then pastes everything as values to a flat workbook, and saves as a reference file. A reference file needs to be created for each .csv file existing in the specified directory. Whilst I can write a macro to open specific files (courtesy of your message board - thanks!), I now need to put some 'intelligence' into it.

Can you help me with this, please?

Kind regards,

Rob.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Use the Dir function like this:

Code:
Sub Test()
    Dim FoundFile As String
    Dim FileSpec as String
    FileSpec = "C:TEMP*.CSV"
    FoundFile = Dir(FileSpec)
    If FoundFile = "" Then Exit Sub
    '*** Your code to process first Foundfile goes here***
    Do While FoundFile <> ""
        FoundFile = Dir()
        If FoundFile <> "" Then        
            '*** Your code to process next FoundFile goes here***
        End If
    Loop
End Sub

Change the FileSpec to suit.
 
Upvote 0

Forum statistics

Threads
1,225,071
Messages
6,182,685
Members
453,132
Latest member
nsnodgrass73

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