Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Macros / December 2007

Tip: Looking for answers? Try searching our database.

Import Excel file to Access

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dp724 - 17 Dec 2007 21:03 GMT
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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.