I'm using the method described by Ken Snell (link below) to import files in
to Access. I've been successful with getting file directory to open, but when
I select a specific file to import, the file that gets imported is the first
file in the directory. How do I edit the code below to just import the file I
select. I don't need to loop through the directory to import all files in the
folder, I only want to import the file selected, so I've removed the loop
statement
http://www.accessmonster.com/Uwe/Forum.aspx/access-macros/6431/Import-from-Excel
l-Macro#C29442DD5241yvonnemichelenoosfr
Code being used:
Private Sub ExcelDataImport_Click()
Dim strDirectory As String, strFilter As String
Dim strFileName As String, strInputFileName As String
strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.XLS)", "*.XLS")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)
strDirectory = Left(strInputFileName, _
InStrRev(strInputFileName, "\"))
strFileName = Dir(strDirectory & "*.xls")
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
"BarChartData", strFileName, True, "AccessData!A1:P101", strFileName =
Dir()
strFileName = Dir()
End Sub
VBA is all new to me and none of editting I've tried out works.
Any help is greatly appreciated.
Dave
dp724 - 17 Dec 2007 21:25 GMT
Ok, I got it working!
Dim strDirectory As String, strFilter As String
Dim strFileName As String, strInputFileName As String
strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.XLS)", "*.XLS")
strInputFileName = ahtCommonFileOpenSave( _
Filter:=strFilter, OpenFile:=True, _
DialogTitle:="Please select an input file...", _
Flags:=ahtOFN_HIDEREADONLY)
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
"BarChartData", strInputFileName, True, "AccessData!A1:P101"
>I'm using the method described by Ken Snell (link below) to import files in
>to Access. I've been successful with getting file directory to open, but when
[quoted text clipped - 33 lines]
>
>Dave
Ken Snell (MVP) - 23 Dec 2007 20:02 GMT
Sorry about the erroneous info in my original post's code. Glad you got past
it and put the correct code together.

Signature
Ken Snell
<MS ACCESS MVP>
> Ok, I got it working!
>
[quoted text clipped - 53 lines]
>>
>>Dave