how to open an excel file with an unknown name

D

Daniel M

I want to open an excel file from access but i may not know the name of the
file. I have a folder "imports" where i want to dump files into. In access i
want to click a button and open up any files in this folder, run an excel
macro on them and then import them into access. I can do all of this except i
have the file name hardcoded. is there a way to open up the file without
knowing the name? usually there will only be 1 file in the folder but could
be 2 or 3 if someone is running behind. I may end up just automatically
processing files on a timed schedule later but for now i have a command
button.

thanks.
 
D

Douglas J. Steele

Dim strFolder As String
Dim strFile As String

strFolder = "C:\SomeFolder\SomeOtherFolder\"
strFile = Dir(strFolder & "*.xls")
Do While Len(strFile) > 0
' At this point, strFolder & strFile will be the full path to a
' file in that folder. Put your existing code here, except
' replace the currently hard-code file name with
' strFolder & strFile.


strFile = Dir()
Loop
 
D

Daniel M

Will this return more than one file name? I see the loop but will it know it
already returned one name and return another name the next time? thanks.
 
D

Douglas J. Steele

It will return each file name once inside the loop.

(wouldn't it have been faster just to test, rather than post and wait for an
answer?)
 
Top