Results 1 to 6 of 6
  1. #1
    cowboy is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    291

    VBA to get info from excel


    Can anyone point me to an example of code that will get information from an excel file?

    Thanks.

  2. #2
    slow&steady is offline Novice
    Windows XP Access 2003
    Join Date
    Jun 2010
    Posts
    3
    one way of doing it is to import the excel file as a table into access

  3. #3
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    try DoCmd.TransferSpreadsheet

    Example:

    DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel8, "Sheet1", "C:\test.xls", True, "Sheet1$"

    Green: Name of the table in the database in which the info will be saved.
    Blue: Complete Path reference of the xls file with the file name and extension.
    Red: Reference to the Sheet on the workbook from which data is to be imported.

  4. #4
    cowboy is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    291
    That worked great, is there anyway to make the sheet just be the first sheet without knowing the name of the sheet?

  5. #5
    cowboy is offline Competent Performer
    Windows XP Access 2003
    Join Date
    Jan 2010
    Posts
    291
    Now that I am thinking about it, the sheet name is always the last part of the file path I am passing which is your Blue Item. For example:

    C:\Documents and Settings\blah\Desktop\Personal\exfile.xls

    The excel sheet seems to name itself the same as the file name, in this case exfile, I have the whole path saved as a variable, how do I break that variable down into just the file name?

  6. #6
    maximus's Avatar
    maximus is offline Expert
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    if you don't put the range data from the first sheet is imported.

    Regarding your second question its not clear to me what you want to do. anyways if this solves your problem mark the thread solved.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Saving info to the database
    By dalton in forum Access
    Replies: 1
    Last Post: 06-02-2010, 08:32 PM
  2. Replies: 8
    Last Post: 04-21-2010, 06:43 AM
  3. Print next 8 days & info
    By skippernick in forum Reports
    Replies: 2
    Last Post: 04-06-2010, 12:38 PM
  4. Getting Info From Tables with Queries
    By SteveI in forum Queries
    Replies: 0
    Last Post: 03-01-2010, 08:33 AM
  5. SQL- retrieving info
    By jmarti57 in forum Programming
    Replies: 0
    Last Post: 12-10-2008, 03:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums