Results 1 to 6 of 6

Thread: [FAQ's: OD] How do I transfer data between Access and Excel?

Threaded View

  1. #1

    Thread Starter
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    [FAQ's: OD] How do I transfer data between Access and Excel?

    Using the TransferSpreadsheet method of the DoCmd object is the easiest method for transfering data between Access and Excel.

    It only takes a few arguments.


    Expression.DoCmd.TransferSpreadsheet TransferType, SpreadsheetType, TableName, FileName, HasFieldNames, Range, UseOA

    TransferType: (acExport, acImport, acLink )
    Specifies the direcion of the transfer.

    SpreadsheetType: (acSpreadsheetTypeExcel3, acSpreadsheetTypeExcel4, acSpreadsheetTypeExcel5, acSpreadsheetTypeExcel7, acSpreadsheetTypeExcel8, acSpreadsheetTypeExcel9, acSpreadsheetTypeLotusWK1, acSpreadsheetTypeLotusWK3, acSpreadsheetTypeLotusWK4)
    Specifies the filetype and version. This depends on the filters and converters that you may have optionally selected during Access/Office installation.

    TableName: (Variant - Access Object)
    This specifies the Access Object that will be used as the source/destination depending upon the first argument supplied.
    It can be a Table or Query to be Exported from or just a Table to be imported to.

    FileName: (Variant - filepath\name)
    Depending on the first argument this will be either the file to export the database objects conetents into or the source file for use in an import operation.

    HasFieldNames: (Variant - True/False)
    Specifies that the first row of the spreadsheet as field names when importing or linking. Use False to identify the first row of the spreadsheet as normal data.

    Range: (Variant - Range)
    A valid range of cells or the name of a range in the spreadsheet. Applies only to importing. Leave this argument blank to import the entire spreadsheet. When you export to a spreadsheet, you must leave this argument blank.

    UseOA: (Variant)
    This argument is not supported.


    Access 2003 VBA Export Code Example:
    Export an Access Table to an Excel Sheet:

    VB Code:
    1. 'Behind an Access VBA Form
    2. Private Sub Command1_Click()
    3.     Application.DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, "Table1", "C:\Book1.xls", False, "Sheet2$"
    4. End Sub
    Access 2003 VBA Import Code Example:
    Import an Excel Sheet to an Access Table:

    VB Code:
    1. 'Behind an Access VBA Form
    2. Private Sub Command1_Click()
    3.     Application.DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, "Table1", "C:\Book1.xls", False, "A1:D8"
    4. End Sub
    Last edited by RobDog888; Aug 23rd, 2006 at 04:03 PM.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width