Open file when I don't know name

acollins

Board Regular
Joined
Aug 1, 2007
Messages
63
I am trying to automate a process where I download orders from a web site in an Excel spreadsheet, then copy the transactions to another sheet which has macros that reformat the data and save them as a fixed-length text file. Problem is - I don't know what the file name is going to be (it is different every time you download).

If I know what folder to look in, is there a way using VBA to read in the file name and save to a variable that I can use to open the file? I plan on only having one file in this folder at any given time - I plan to have my routine clean up after itself when I am done. I figure it will probably be easier to write the routine if I know that I can just look in the folder and grab whatever Excel file it sees out there. I'm just not sure how to go about writing it.

Any help appreciated.

Thanks!

Alan
 

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)
Alan

Only 1 file in the folder?

Always the same folder?
Code:
strFolder = "C:\TheFolder\"
 
strFileName = Dir(strFolder & "*.*")
 
Set wbOpen = Workbooks.Open(strFolder & strFileName)
 
' rest of code
 
Upvote 0
Thanks for the quick reply, Norie. This should work nicely although I probably won't have a chance to test it until the first of the week. I'll let you know then how it works out.
 
Upvote 0

Forum statistics

Threads
1,221,590
Messages
6,160,668
Members
451,662
Latest member
reelspike

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