Import file with name changing daily

fraudit

New Member
Joined
Jan 14, 2015
Messages
11
I'd like to automate creating an Excel spreadsheet built by several files (stored in different sheets), including a daily export file in CSV format. My problem is that this CSV file has date as a part of its name (all other files are named without any changing parts), e.g. REPORT_20150216.csv.

Is there a way to build a wildcard (or similar) import mechanism that would look for files whose filenames start with REPORT? I've tried to put "REPORT*.csv, but it didn't work :(. At the moment I simply created a single Application.GetOpenFilename entry for this particular file, but it would be perfect to have it imported automatically, without manual selection.

For other files I'm using the simplest code:
Code:
  With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;C:\Users\myusername\Desktop\myfilename.csv", Destination:=Range("$A$1"))
followed by respective parameters.

Is there a way to play with a wildcard here?
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
OK, by gathering several tips from VBA forums I've come with the following, non-working, code:
Code:
With ActiveSheet.QueryTables.Add(Connection:= _
        "TEXT;C:\Users\myusername\Desktop\REPORT_" & Format(Date, "yyyymmdd") & ".csv*", Destination:=Range("$A$1"))
The problem is that by running it I'm receiving well-known 1004 error and while debugging I'm getting the following part of the code highlighted:
Code:
.Refresh BackgroundQuery:=False

Anyone is able to assist me with that?
 
Upvote 0

Forum statistics

Threads
1,215,364
Messages
6,124,510
Members
449,166
Latest member
hokjock

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