Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Community Wiki

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Navigation

Google Ads

Import All Excel Worksheets to Separate Tables in Access

From Wiki

Jump to: navigation, search

It is possible to import all worksheets without knowing the names by using automation.

  1. Sub GetExcel()
  2.    'Requires reference to the Microsoft Excel x.x Object Library
  3.    
  4.    Dim strFileName As String
  5.    Dim objXL As Excel.Application 'Object
  6.    Dim wkb As Excel.Workbook
  7.    Dim wks As Object
  8.    
  9.    Set objXL = CreateObject("Excel.Application")
  10.    'objXL.Visible = True
  11.    
  12.    strFileName = "C:\Docs\LTD.xls"
  13.    Set wkb = objXL.Workbooks.Open(strFileName)
  14.    
  15.    For Each wks In wkb.Worksheets
  16.       DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
  17.             wks.Name, strFileName, True, wks.Name & "$"
  18.    Next
  19.    
  20.    'Tidy up
  21.    wkb.Close
  22.    Set wkb = Nothing
  23.    objXL.Quit
  24.    Set objXL = Nothing
  25.  
  26. End Sub

30Jun08 Caveat: In my experience, this sort of approach will truncate all text strings at 255 characters. It seems the only reliable method, if your colleagues insist on treating Excel as a word processor *ahem* is to use Automation and explicitly acquire an Excel.Range for each cell.

I would merrily accept correction on the point. --smitty1e

In reply: If the memo-type data is in or below the 27th row (tested in Access 2000, row 1= header), then data will be imported into a text field. This is a problem with all Excel imports in that the data type of the import field is determined by the first few rows. A way around is to import into an existing table. Truncation can also occur if you have not got a recent version of the Jet driver (http://support.microsoft.com/kb/239114).

413 Rating: 2.8/5 (4 votes cast)