How do I import a csv file with wild cards

JeffGrant

Well-known Member
Joined
Apr 7, 2021
Messages
558
Office Version
  1. 365
Platform
  1. Windows
Hi All, and thanks in advance. This a most basic question I am sure.

I have a query which imports a specific file - Main-Report.csv, withthe file path being: C:\Users\...\Input\Main-Report.csv. Which works just fine.

However, when I am back testing, the import file name is Main-Report-dd-mmm-yy.csv

Can somebody please tell me the syntax so that the query will import something like: C:\Users\...\Input\Main-Report*.csv

At the moment, I have having to rename the file and remove the dd-mmm-yy for the query to work. I cant just import all csv files at folder level because there are other csv files in that folder that are not be imported.

cheers
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
One Solution could be to use file selection window to select the specific file your code needs to act upon. This will save your time and efforts to rename manually

VBA Code:
With Application.FileDialog(msoFileDialogFilePicker)
        .InitialFileName = "C:\Users\...\Input\Main-Report*"
        .AllowMultiSelect = False
        .Title = "Please select the Import File"
        If .Show Then ' if OK is pressed
            
            import_file = .SelectedItems(1)
            
        Else
            
            MsgBox ("No File was selected. Now Terminating the execution")
            exit sub
            
        End If
    End With
 
Upvote 0
Solution
Hi Ashish. Thanks very much for that. I will be certain to give it a go. Whilst you were asnwering I also found this great solution at..

 
Upvote 0
Hi Ashish, just tested and am now using your code to fix another very annoying issue that I had.

Thanks man. Perfect! :-)
 
Upvote 0

Forum statistics

Threads
1,223,669
Messages
6,173,700
Members
452,527
Latest member
ineedexcelhelptoday

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