Results 1 to 3 of 3
  1. #1
    sportyaccordy is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    7

    Adding sheet & file names to Excel import

    Hello,



    I have a big collection of weekly spreadsheets I'd like to import into one big table. That is no problem, I know how to loop through imports in a folder. The issue I have is I'd like to add an identifier of each tab and file. So for the basic code I am thinking:

    Code:
    [Initialized variables etc etc]
    folder = [where files are] filename = Dir(folder & "*[common string in file names]*")
    Do While filename <> ""
    For each element in Array( [list of worksheet names]) DoCmd.TransferSpreadsheet acImport, 10, [Access Table], folder & filename, True, '[element]'![copy range] [Add worksheet name to extra field] [Add piece of file name to another extra field] Next element filename = Dir()
    Loop
    So the output would look like this:

    Imported Data Headers Worksheet Name Workbook Name
    Imported Data WSName1 WSFile1
    Imported Data WSName2 WSFile1
    Imported Data WSName1 WSFile2
    Imported Data WSName3 WSFile2
    Imported Data etc. etc.

    Any ideas?

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    the column headers are in the query, then

    docmd.TransferSpreadsheet acExport ,acSpreadsheetTypeExcel12,vQryName, vFILENAME, true, vSHEETNAME

    (or acImport)

  3. #3
    sportyaccordy is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jul 2016
    Posts
    7
    I don't think I'm asking the question clearly. Basically I want to do an acImport, and then add the name of the file and sheet of each import to every record.

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

Similar Threads

  1. Replies: 2
    Last Post: 11-21-2018, 05:53 AM
  2. Replies: 5
    Last Post: 04-25-2017, 01:38 AM
  3. Replies: 10
    Last Post: 06-16-2014, 08:37 AM
  4. Replies: 3
    Last Post: 08-15-2012, 04:15 PM
  5. Change Excel Sheet Names
    By qwerty1 in forum Access
    Replies: 4
    Last Post: 06-12-2012, 09:53 AM

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