Access not importing excel file

  • Remove From My Forums
  • Question

  • problem:

    I’ve just got Microsoft Access up and running — but it won’t import xls files, just giving message:

    «The wizard is unable to access the information in the file….. Please check that the file exists and is in the correct format.»

    I also tried opening the same file in Excel and got this message:

    «the file format and extension of ‘_____.xls’ don’t match. The file could be corrupted or unsafe. Unless you trust its source, don’t open it. Do you want to open it anyway?»

    When I click yes there, it does open. But not in Access.

    If, once open in Excel, I go to File>Export>Change File Type — and export as either «Workbook» or «Excel 97-2003 Workbook,» those files WILL open in Access. Yet, doing this for every single sheet I need to import into Access is
    an impractical hassle.

    any idea on why Access won’t open the xls file and/or what settings I may need to adjust so it will?

    thanks!!

Answers

  • thanks, Emi.

    the excel files I’m trying to work with, are being downloaded via Facebook Business Manager as an exported report — so I guess the only solution is to convert them before importing to Access, whether by opening in Excel and resaving/exporting as xlsx or
    using a converter to do them in bulk…

    • Proposed as answer by

      Monday, February 15, 2016 2:30 AM

    • Marked as answer by
      Emi ZhangMicrosoft contingent staff
      Monday, February 15, 2016 6:05 AM

  • Remove From My Forums
  • Question

  • Using Access 2000, I’m trying to import a table from an Excel 97-2003 spreadsheet. The spreadsheet is not that big, 5 columns, and about 200 rows. No nulls, the data is very straightforward.

    When I use the wizard and select the Excel spreadsheet, I am getting a message: File ‘ABC.xls’ does not contain data.  And then I get kicked out of the wizard. The spreadsheet does indeed have data.

    My workaround is to make a backup copy of the «bad» spreadsheet, delete the original. Copy a previous month and rename to the filename I deleted, and delete all contents. Then copy the contents in the backup to the blank copy, which is now the
    good copy. And that works. Very bizarre.

    Any ideas?

Answers

  • I think the main problem is that you use Access 2000 and presumably Excel 2000 / driver for Excel 2000 installed on your computer.  The third party may be using a later version of Excel to create the file. It then becomes a hit & miss
    affair depending on the meta-data embedded in the Excel file. 

    While there is only 1 common file format «Excel (97-2003)» (see note later), a later Excel version will write the file slightly different from the earlier Excel versions to cater for new features.  When this file (created by the later Excel
    version) is read by the earlier versions, this type of problem occasionally occurs. 

    Unfortunately, you won’t be able to find any Microsoft update for Office 2000 anymore since standard support and even paid extended support have ended some time ago.

    If you have another PC that use Office 2003 or later, try processing the Excel file on this PC and see if you encounter the same problem.

    *** Note re «Excel (97-2003)» file format:  If you look at the TransferSpreadsheet Method in a later Access version, the (relevant) valid values for the SpreadsheetType argument are:

    acSpreadsheetTypeExcel8 (Excel97)

    acSpreadsheetTypeExcel9 (Excel2000)

    so you can see there must be some differences in the way the Excel file is written and read between versions even though supposedly the same common format «Excel (97-2003)».


    Van Dinh

    • Edited by

      Wednesday, July 3, 2013 4:56 PM
      Typos

    • Marked as answer by
      JMANCI
      Wednesday, July 3, 2013 6:35 PM

  • I tried to do the .csv, but that was not behaving well with some of the data in the Excel spreadsheet.

    I looked at the format of the Excel file. Now, I’m pretty sure that we picked the 97-2003 format instead of the 2010 format so that it would work with Access 2000, but when I checked, the format was showing as Excel 5.0/95.  Once I changed
    the format to 97-2003, I was able to import without a problem. I’ll double-check this process next month, but I think I am ok for now. Thanks.

    • Marked as answer by
      JMANCI
      Wednesday, July 3, 2013 6:35 PM


Download Article


Download Article

Access is a relational database manager that allows you to import one or multiple Excel databases into its system so you can match common fields between or among them. Because a single Access file can contain multiple Excel spreadsheets, the program is also a great way to aggregate or analyze large amounts of information. First, though, you need to import the Excel spreadsheet into Access. This only requires a few key steps.

Things You Should Know

  • Before you import your spreadsheet into Access, make sure you have clear column headers in the first row so they can easily translate to field names.
  • Scan multi-page workbooks to make sure each type of data is handled the same way across all sheets.
  • The Access import wizard makes it easy to import your data in a way that Access can understand.
  1. Image titled Import Excel Into Access Step 1

    1

    Open both programs on your computer. You will need to purchase and download a Microsoft Office package that includes both Excel[1]
    and Access. You can do this online through the Microsoft site.

    • Once the programs are downloaded, click «Start» in Windows and select «All Programs.»[2]
    • Click on «Microsoft Office,» and then select «Access» (or «Excel») from the drop-down menu. You may already have an Excel spreadsheet created that someone else sent you or that you downloaded from elsewhere. Having Office on your computer allows you to open it.
  2. Image titled Import Excel Into Access Step 2

    2

    Clean up your Excel spreadsheet before importing it into Access. It will make it easier if you do a few simple steps before you import the Excel spreadsheet into Access. The key is that your data must be consistent between imported spreadsheets.[3]

    • It’s a good idea to make sure that the first row in the Excel spreadsheet contains your column headers (or field names), and that these are very clear and easy to understand.[4]
      For example, for a column containing people’s last names, you may want to call the column header/field name «last name.» Be clear and precise because it will make it easier when you try to match column headers in one Excel sheet with another.
    • Access allows you to link common fields between two or among many spreadsheets. Let’s say you have an Excel sheet that contains payroll information. It includes people’s first and last names, addresses, and salaries. Let’s say for the sake of argument that you want to match that sheet within Access to a second Excel sheet that contains information about campaign finance contributions. This second sheet contains people’s names, addresses, and donations. What Access allows you to do is to match different column headers with one another. You could link name headers to see which people of the same name appear in both databases, for example.
    • Scan the Excel sheets to make sure that each type of data is handled the same way, and clean it up before importing it into Access.[5]
      It must be what Access calls «relational.» For example, if the hypothetical spreadsheet for payroll contained first name, last name and middle initial in one column, but the second spreadsheet contained only first name and last name in separate columns, Access will register this as no match. There needs to be matching column headers/fields.

    Advertisement

  3. Image titled Import Excel Into Access Step 3

    3

    Split information within a column in Excel. To take care of this issue, you may want to split information in a column within Excel, so that it doesn’t erroneously register as a «no match» in Access.

    • As an example, you may want to split the first name into its own column, the middle initial into its own column, and the last name into its own column. If it’s already done the same way in the second spreadsheet, when you link, say, last name with last name in Access, it should generate matches when the names are the same.
    • To split a column in Excel, highlight the column that has information you want to split in it. Click on «data»in the toolbar within the Excel program. Click on «text to columns.» Generally, you will choose the option «delimited.» Click next.
  4. Image titled Import Excel Into Access Step 4

    4

    Continue using the wizard to split merged columns. Now you are ready to complete the process of splitting merged information in one column into multiple columns.

    • Choose how the data within the column is «delimited.» This means that each piece of information in the column is separated by something. Most common choices include a space, a comma, or a semi-colon. Often the information is just separated by a space. As in the following example: let’s say the name «John A. Doe» appears in a single column. The first name John is separated from the middle initial A by a space. The last name Doe is separated from the middle initial A by a space. So choose space in the delimited wizard.
    • Click next. Click finish. The program should split John, A., and Doe into three columns. You can then give the new columns new header names to indicate the kind of information housed in them (last name, first name, etc.). It’s a good idea to create several blank columns to the right of the data you’re splitting before you do it because it will push the data into the new blank columns (instead of columns that already contain information).
  5. Advertisement

  1. Image titled Import Excel Into Access Step 5

    1

    Open the Access program on your computer. Go to the start menu, choose Microsoft Office, and click on Microsoft Access. You need to open a new blank Access database to import the Excel sheet into it.

    • Choose «blank desktop database» to create a new database within the Access program.
    • Give it a new name if you want. Click «create.»
  2. Image titled Import Excel Into Access Step 6

    2

    Import an Excel spreadsheet into Access. The next step is to pull the Excel spreadsheet (or more than one) into the Access database.

    • Click on «External Data» in the toolbar once you are within the Access database manager. Choose «Excel.»[6]
      In some versions of Access, you will find this function by clicking on «file» in the toolbar and «Get External Data.»[7]
    • Where it says «file name,» click «browse.» This will allow you to find your Excel sheet on your computer.
    • Leave the box checked that says «import the source data into a new table in the current database.» It will be checked by default.
    • When you find the Excel spreadsheet you want to import on your computer, click on it. Click «OK.» This will take you into the wizard for importing Excel into Access.
  3. Advertisement

  1. Image titled Import Excel Into Access Step 7

    1

    Go through the steps on the wizard that appears within Access. To complete the process of importing your spreadsheet, you need to complete the steps in the wizard.

    • Choose the worksheet within the Excel spreadsheet that you want to import. Sometimes, this is simple because the Excel spreadsheet is just one sheet. However, sometimes people create multiple pages within a single Excel spreadsheet, which you can see by clicking on the tabs at the bottom of the spreadsheet. If this is the case, you need to tell the Access wizard which spreadsheet you are choosing. Click next.
    • The next page has a box asking if the first row in the Excel sheet has column headings. This means the row in a spreadsheet that identifies the data in each column (such as last name, address, salary, etc.). It’s a good idea if you cleaned up your Excel sheet first to make sure that the first row has clearly defined column headings. Then, just check yes that the first row contains column headings. This is the simplest approach. Click next.
    • If your first row does not contain column headings, the next page asks you if you want to rename what are called «fields» in Access (these are column headings). If you did not already name each field something clear and easy to recognize before importing (recommended), then you can do it here.
  2. Image titled Import Excel Into Access Step 8

    2

    Finish the importing process. There are only a few steps left in the importing process. The next page in the wizard will ask if you want to identify a primary key.

    • You don’t have to do this, but you can. A primary key means the computer program will assign each row of information a unique number. This can be helpful later on when sorting the data. Click next.[8]
    • The final screen in the wizard has a space providing a default name. You can change the name of the Excel sheet you are importing (it will become a «table» in Access on the left side of the page when you finish importing it).
    • Click «import.» Click «close.» You will see your table on the left side of the screen. It is now imported within Access.
    • If you want to link more than one data set, repeat this process with another or multiple Excel spreadsheets. Now, you are ready to match the data in the sheets within Access.
  3. Advertisement

Ask a Question

200 characters left

Include your email address to get a message when this question is answered.

Submit

Advertisement

Video

Thanks for submitting a tip for review!

  • If the Excel file is from a different version of Office than Access, you may have trouble importing files smoothly.

  • It can’t be underscored enough: You need to clean up your Excel spreadsheet before importing it. Partly this means analyzing the data you have for problems.

  • Always keep a copy of your original spreadsheets, so if you mess them up, you can repeat the process.

  • You can not import more than 255 fields into Access.[9]

Advertisement

About This Article

Thanks to all authors for creating a page that has been read 263,833 times.

Is this article up to date?

Can you export from Excel to Access using ADO???

Sub ADOFromExcelToAccess()
' exports data from the active worksheet to a table in an Access database
' this procedure must be edited before use
Dim cn As ADODB.Connection, rs As ADODB.Recordset, r As Long
    ' connect to the Access database
    Set cn = New ADODB.Connection
    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0; " & _
        "Data Source=C:FolderNameDataBaseName.mdb;"
    ' open a recordset
    Set rs = New ADODB.Recordset
    rs.Open "TableName", cn, adOpenKeyset, adLockOptimistic, adCmdTable  
    ' all records in a table
    r = 3 ' the start row in the worksheet
    Do While Len(Range("A" & r).Formula) > 0 
    ' repeat until first empty cell in column A
        With rs
            .AddNew ' create a new record
            ' add values to each field in the record
            .Fields("FieldName1") = Range("A" & r).Value
            .Fields("FieldName2") = Range("B" & r).Value
            .Fields("FieldNameN") = Range("C" & r).Value
            ' add more fields if necessary...
            .Update ' stores the new record
        End With
        r = r + 1 ' next row
    Loop
    rs.Close
    Set rs = Nothing
    cn.Close
    Set cn = Nothing
End Sub

Can you do the same using DAO???

Sub DAOFromExcelToAccess()
' exports data from the active worksheet to a table in an Access database
' this procedure must be edited before use
Dim db As Database, rs As Recordset, r As Long
    Set db = OpenDatabase("C:FolderNameDataBaseName.mdb") 
    ' open the database
    Set rs = db.OpenRecordset("TableName", dbOpenTable) 
    ' get all records in a table
    r = 3 ' the start row in the worksheet
    Do While Len(Range("A" & r).Formula) > 0 
    ' repeat until first empty cell in column A
        With rs
            .AddNew ' create a new record
            ' add values to each field in the record
            .Fields("FieldName1") = Range("A" & r).Value
            .Fields("FieldName2") = Range("B" & r).Value
            .Fields("FieldNameN") = Range("C" & r).Value
            ' add more fields if necessary...
            .Update ' stores the new record
        End With
        r = r + 1 ' next row
    Loop
    rs.Close
    Set rs = Nothing
    db.Close
    Set db = Nothing
End Sub

Can you import to Access form a closed Workbook???

GetDataFromClosedWorkbook "C:FolderNameWorkbookName.xls", "A1:B21", ActiveCell, False
GetDataFromClosedWorkbook "C:FolderNameWorkbookName.xls", "MyDataRange", Range ("B3"), True

Sub GetDataFromClosedWorkbook(SourceFile As String, SourceRange As String, _
    TargetRange As Range, IncludeFieldNames As Boolean)
' requires a reference to the Microsoft ActiveX Data Objects library
' if SourceRange is a range reference:
'   this will return data from the first worksheet in SourceFile
' if SourceRange is a defined name reference:
'   this will return data from any worksheet in SourceFile
' SourceRange must include the range headers
'
Dim dbConnection As ADODB.Connection, rs As ADODB.Recordset
Dim dbConnectionString As String
Dim TargetCell As Range, i As Integer
    dbConnectionString = "DRIVER={Microsoft Excel Driver (*.xls)};" & _
        "ReadOnly=1;DBQ=" & SourceFile
    Set dbConnection = New ADODB.Connection
    On Error GoTo InvalidInput
    dbConnection.Open dbConnectionString ' open the database connection
    Set rs = dbConnection.Execute("[" & SourceRange & "]")
    Set TargetCell = TargetRange.Cells(1, 1)
    If IncludeFieldNames Then
        For i = 0 To rs.Fields.Count - 1
            TargetCell.Offset(0, i).Formula = rs.Fields(i).Name
        Next i
        Set TargetCell = TargetCell.Offset(1, 0)
    End If
    TargetCell.CopyFromRecordset rs
    rs.Close
    dbConnection.Close ' close the database connection
    Set TargetCell = Nothing
    Set rs = Nothing
    Set dbConnection = Nothing
    On Error GoTo 0
    Exit Sub
InvalidInput:
    MsgBox "The source file or source range is invalid!", _
        vbExclamation, "Get data from closed workbook"
End Sub

Finally…can you browse to an Excel file and import data from that file???

Dim strPathFile As String
Dim strTable As String, strBrowseMsg As String
Dim strFilter As String, strInitialDirectory As String
Dim blnHasFieldNames As Boolean

' Change this next line to True if the first row in EXCEL worksheet
' has field names
blnHasFieldNames = False

strBrowseMsg = "Select the EXCEL file:"

' Change C:MyFolder to the path for the folder where the Browse
' window is to start (the initial directory). If you want to start in
' ACCESS' default folder, delete C:MyFolder from the code line,
' leaving an empty string as the value being set as the initial
' directory
strInitialDirectory = "C:MyFolder"

strFilter = ahtAddFilterItem(strFilter, "Excel Files (*.xls)", "*.xls")

strPathFile = ahtCommonFileOpenSave(InitialDir:=strInitialDirectory, _
      Filter:=strFilter, OpenFile:=False, _
      DialogTitle:=strBrowseMsg, _
      Flags:=ahtOFN_HIDEREADONLY)

If strPathFile = "" Then
      MsgBox "No file was selected.", vbOK, "No Selection"
      Exit Sub
End If

' Replace tablename with the real name of the table into which
' the data are to be imported
strTable = "tablename"

DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
      strTable, strPathFile, blnHasFieldNames

' Uncomment out the next code step if you want to delete the
' EXCEL file after it's been imported
' Kill strPathFile

Try these examples and post back with your findings.

  • #2

Instead of importing your Excel Data, I suggest you link your excel table to Access.

  • #3

Instead of importing your Excel Data, I suggest you link your excel table to Access.

Hi just curious how is this a better solution? I don’t know if it helps but what I am trying to do is build database for equipment that I constantly have to conduct inventory of.
the excel files that I have to constantly import (once a week) may or may not have new equipment added to it everything is tracked by serial number (key)

I just want to hit a button have access prompt to fileopen a new excel report and analyze weather there’s new equipment to add to my db based on serial number
this prevents me from having to manually enter a large quantity of new equipment one at a time into access since Im getting the data straight from the source which happens to export excel reports

Hope that explanation helps

Joe4

Joe4

MrExcel MVP, Junior Admin


  • #4

Importing data directly from Excel has always been a little tricky. One of the issues is Excel and Access «talk to each other», and try to figure out things for you, instead of letting you do it, and they sometimes «guess» wrong (especially when it comes to data type). I believe it looks at the first 10 rows of data to «guess» what the data type is. So sometimes, it picks the wrong things.

What I have often done in the past is export my Excel file to a text file and import that, where I can have full control over all the fields and data tyes.

However, if you have an Excel file that is constantly being updated, you can use the method that Alan described (linking the Excel file). Then any changes to the Excel file are automatically updated in Excel (since all the data is linked). If for some reason you need to keep the data separate (maybe once it is in Access, you may make edits to it that are not reflected on the Excel file), what you can do is link the Excel file to Access in a «temporary» table, and then do an Unmatched Query from the «temporary» table to your final table in Access, to locate all the new records. Then use an Append Query to add those new records to your final Access table (the «Unmatched» and «Append» Query can be one and the same).

On your final table, I would also recommend that you set primary key fields, which will prevent you from overwriting existing records in your final table.

  • #5

@Carlit007: If you link, Access will probably replace period with #. That is what I’d do. To make the suggested data table, use the linked sheet in a make table query and you’ll get your table quickly. Then close the mt query (if it worked, you don’t even need to save it). Then open the new table in design and fix the data types and names if required. I would describe the method of preventing records as making sure you have unique indexes, not primary fields. While 2 or more fields can be used to make a composite primary key, it’s better to have either one or more indexes or a composite index as well as one PK field in your data table.

Another way to get data into the table is to simply run an append query, and any attempt to append records that violate data integrity will be rejected. However, you need those unique indexes to prevent that. For instance, if the append contains work order numbers (WO) and your unique index is on that field, you will not append the same number again. You will get a message about the failure of the query to perform as Access thinks you intended. I mention this because it’s easier than creating outer joins, not that it’s a better way. Further to the the given example of WO index, if your index comprises WO and TaskNo fields, then you can append the same work order several times, but only where the combination of WO and task number to be appended does not already exist in your data table.

In your new table, there should be no spaces or special characters in any object name in Access (save for underscore, which I almost never use either). If you are not familiar with proper naming convention for Access, I suggest you research it. I’ll also suggest that you research db normalization because those who switch from Excel to Access almost always start off with poorly designed tables and struggle thereafter. These apps look similar but you would do well to not use them they same way.

  • #6

@Carlit007: If you link, Access will probably replace period with #. That is what I’d do. To make the suggested data table, use the linked sheet in a make table query and you’ll get your table quickly. Then close the mt query (if it worked, you don’t even need to save it). Then open the new table in design and fix the data types and names if required. I would describe the method of preventing records as making sure you have unique indexes, not primary fields. While 2 or more fields can be used to make a composite primary key, it’s better to have either one or more indexes or a composite index as well as one PK field in your data table.

Another way to get data into the table is to simply run an append query, and any attempt to append records that violate data integrity will be rejected. However, you need those unique indexes to prevent that. For instance, if the append contains work order numbers (WO) and your unique index is on that field, you will not append the same number again. You will get a message about the failure of the query to perform as Access thinks you intended. I mention this because it’s easier than creating outer joins, not that it’s a better way. Further to the the given example of WO index, if your index comprises WO and TaskNo fields, then you can append the same work order several times, but only where the combination of WO and task number to be appended does not already exist in your data table.

In your new table, there should be no spaces or special characters in any object name in Access (save for underscore, which I almost never use either). If you are not familiar with proper naming convention for Access, I suggest you research it. I’ll also suggest that you research db normalization because those who switch from Excel to Access almost always start off with poorly designed tables and struggle thereafter. These apps look similar but you would do well to not use them they same way.

@Micron thanks you for the advice I understand the advantages of linking instead of importing a little e better now I did spend all night researching about importing with query by using append I was able to get it to work when importing new records I need to work on getting all the fields besides the keys to populate into the existing data not sure If the headers have to always match or if I can reroute in the append to: field under query

I will definitely go and spend some time learning Db normalization because my way of thinking is still stuck on excel for the most part :)

  • #7

I would like to know if by using vba I could make a button in a form that lets me import data with a file open dialog that lets me choose the file to import and to what table to import to.
and upon import it clears any ilegal character from the excel headers so that it gets properly imported into the right field

yes, just write an access script that copies the excel file. then edits the copy so that the column headers are more database friendly
Admin no. becomes admin_number and so on
and then import the copy
then delete the copy

  • #8

Then there is automation. For that, I go to here

  • #9

Then there is automation. For that, I go to here

@ Micron thanks for providing that link!
its like a treasure chest full of information for the functionalities I need for by DB many Thanks

Понравилась статья? Поделить с друзьями:
  • A word that means using big words
  • A word that means unique and different
  • A word that means to stick to
  • A word that means to put off
  • A word that means to not want to do something