PC Review


Reply
Thread Tools Rate Thread

How do I import a collection of Excel files each containing multip

 
 
KramerJ
Guest
Posts: n/a
 
      17th Mar 2009
How do I import into Access 2003 a collection of Excel files each containing
multiple work sheets.
 
Reply With Quote
 
 
 
 
ryguy7272
Guest
Posts: n/a
 
      17th Mar 2009
Import all files into one table (probably not a good idea). But anyway...
Map to the folder that the files are in now:
below, I called ithe folder Import, loke this:
strPath = "C:\Import\"

Sub ImportAllExcelFiles()
On Error GoTo Err_F
Dim strPathFile As String, strFile As String, strPath As String, strSpec As
String
Dim strTable As String, ynFieldName As Boolean
ynFieldName = False
strPath = "C:\Import\"
'strSpec = "NameOfImportSpecification" ' Put your name here
strTable = "tablename"
strFile = Dir(strPath & "*.xls")
Do While Len(strFile) > 0
strPathFile = strPath & strFile
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, strTable,
strPathFile, ynFieldName
' Uncomment out the next code step if you want to delete the file after it's
imported
' Kill strPathFile
strFile = Dir()
Loop
Exit_F:
Exit Sub

Err_F:
MsgBox Err.Number & " " & Err.Description
Resume Exit_F

End Sub

If you want to import to several Tables, and you name the Tables as the code
runs, try this:

Function ImportFiles()
Dim strPathFile As String, strFile As String, strPath As String
Dim strTable As String
Dim blnHasFieldNames As Boolean
blnHasFieldNames = True
strPath = "C:\Import\"
strFile = Dir(strPath & "*.xls")
Do While Len(strFile) > 0
strPathFile = strPath & strFile
'Name the table
strTable = InputBox("Enter table name for file """ & strPathFile & """")
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
strTable, strPathFile, blnHasFieldNames
strFile = Dir()
Loop
MsgBox "Done with Import"
End Function

Call the function this way:
Private Sub Command0_Click()
Call ImportFiles
End Sub

Regards,
Ryan---

--
RyGuy


"KramerJ" wrote:

> How do I import into Access 2003 a collection of Excel files each containing
> multiple work sheets.

 
Reply With Quote
 
KramerJ
Guest
Posts: n/a
 
      17th Mar 2009
Many thanks, expecially the quick reply. Reason for importing all worksheets
from each workbook is to create a master Access table to automate the
conversion process and for further database development. I have been out of
the mainstream of development awhile so I am thankful for your assisstance.
Regards, Joe

"ryguy7272" wrote:

> Import all files into one table (probably not a good idea). But anyway...
> Map to the folder that the files are in now:
> below, I called ithe folder Import, loke this:
> strPath = "C:\Import\"
>
> Sub ImportAllExcelFiles()
> On Error GoTo Err_F
> Dim strPathFile As String, strFile As String, strPath As String, strSpec As
> String
> Dim strTable As String, ynFieldName As Boolean
> ynFieldName = False
> strPath = "C:\Import\"
> 'strSpec = "NameOfImportSpecification" ' Put your name here
> strTable = "tablename"
> strFile = Dir(strPath & "*.xls")
> Do While Len(strFile) > 0
> strPathFile = strPath & strFile
> DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, strTable,
> strPathFile, ynFieldName
> ' Uncomment out the next code step if you want to delete the file after it's
> imported
> ' Kill strPathFile
> strFile = Dir()
> Loop
> Exit_F:
> Exit Sub
>
> Err_F:
> MsgBox Err.Number & " " & Err.Description
> Resume Exit_F
>
> End Sub
>
> If you want to import to several Tables, and you name the Tables as the code
> runs, try this:
>
> Function ImportFiles()
> Dim strPathFile As String, strFile As String, strPath As String
> Dim strTable As String
> Dim blnHasFieldNames As Boolean
> blnHasFieldNames = True
> strPath = "C:\Import\"
> strFile = Dir(strPath & "*.xls")
> Do While Len(strFile) > 0
> strPathFile = strPath & strFile
> 'Name the table
> strTable = InputBox("Enter table name for file """ & strPathFile & """")
> DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
> strTable, strPathFile, blnHasFieldNames
> strFile = Dir()
> Loop
> MsgBox "Done with Import"
> End Function
>
> Call the function this way:
> Private Sub Command0_Click()
> Call ImportFiles
> End Sub
>
> Regards,
> Ryan---
>
> --
> RyGuy
>
>
> "KramerJ" wrote:
>
> > How do I import into Access 2003 a collection of Excel files each containing
> > multiple work sheets.

 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      17th Mar 2009
Please click 'Yes', if the post was helpful to you.

--
RyGuy


"KramerJ" wrote:

> Many thanks, expecially the quick reply. Reason for importing all worksheets
> from each workbook is to create a master Access table to automate the
> conversion process and for further database development. I have been out of
> the mainstream of development awhile so I am thankful for your assisstance.
> Regards, Joe
>
> "ryguy7272" wrote:
>
> > Import all files into one table (probably not a good idea). But anyway...
> > Map to the folder that the files are in now:
> > below, I called ithe folder Import, loke this:
> > strPath = "C:\Import\"
> >
> > Sub ImportAllExcelFiles()
> > On Error GoTo Err_F
> > Dim strPathFile As String, strFile As String, strPath As String, strSpec As
> > String
> > Dim strTable As String, ynFieldName As Boolean
> > ynFieldName = False
> > strPath = "C:\Import\"
> > 'strSpec = "NameOfImportSpecification" ' Put your name here
> > strTable = "tablename"
> > strFile = Dir(strPath & "*.xls")
> > Do While Len(strFile) > 0
> > strPathFile = strPath & strFile
> > DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, strTable,
> > strPathFile, ynFieldName
> > ' Uncomment out the next code step if you want to delete the file after it's
> > imported
> > ' Kill strPathFile
> > strFile = Dir()
> > Loop
> > Exit_F:
> > Exit Sub
> >
> > Err_F:
> > MsgBox Err.Number & " " & Err.Description
> > Resume Exit_F
> >
> > End Sub
> >
> > If you want to import to several Tables, and you name the Tables as the code
> > runs, try this:
> >
> > Function ImportFiles()
> > Dim strPathFile As String, strFile As String, strPath As String
> > Dim strTable As String
> > Dim blnHasFieldNames As Boolean
> > blnHasFieldNames = True
> > strPath = "C:\Import\"
> > strFile = Dir(strPath & "*.xls")
> > Do While Len(strFile) > 0
> > strPathFile = strPath & strFile
> > 'Name the table
> > strTable = InputBox("Enter table name for file """ & strPathFile & """")
> > DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
> > strTable, strPathFile, blnHasFieldNames
> > strFile = Dir()
> > Loop
> > MsgBox "Done with Import"
> > End Function
> >
> > Call the function this way:
> > Private Sub Command0_Click()
> > Call ImportFiles
> > End Sub
> >
> > Regards,
> > Ryan---
> >
> > --
> > RyGuy
> >
> >
> > "KramerJ" wrote:
> >
> > > How do I import into Access 2003 a collection of Excel files each containing
> > > multiple work sheets.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen Microsoft ASP .NET 1 18th May 2007 10:24 AM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen Microsoft Dot NET 1 18th May 2007 10:24 AM
how do i quickly import many video files into the same collection =?Utf-8?B?UEQ=?= Windows XP MovieMaker 1 4th Sep 2006 05:23 PM
Import files from folder (excel files) into access tushargarg729@yahoo.com Microsoft Access Macros 0 3rd Oct 2005 09:53 PM
Multip worksheets in Excel 97 marfq Microsoft Excel Worksheet Functions 1 14th May 2004 02:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:09 PM.