PC Review


Reply
Thread Tools Rate Thread

How do I import an Excel file with MULTIPLE WORKSHEETS into Access

 
 
KramerJ
Guest
Posts: n/a
 
      18th Mar 2009
How do I import an EXCEL FILE WITH MULTIPLE WORKSHEETS into Access 2003. I am
creating a master table in Access of archived Excel files, each file has
multiple worksheets. Is there a need to use both SQL and VBA to accomplished
the import. TIA
 
Reply With Quote
 
 
 
 
Ken Snell MVP
Guest
Posts: n/a
 
      18th Mar 2009
Do you know the names of the worksheets in the files? Or do you have to
"read" the worksheet names from the EXCEL files?

If the former is true, you can use the code at this web page as a starting
point. Just add another loop or extra steps for the various worksheets.
Import Data from All EXCEL Files in a single Folder via TransferSpreadsheet
http://www.accessmvp.com/KDSnell/EXC...ImpFolderFiles
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


"KramerJ" <(E-Mail Removed)> wrote in message
news:6E58A88E-0A62-42FA-9E32-(E-Mail Removed)...
> How do I import an EXCEL FILE WITH MULTIPLE WORKSHEETS into Access 2003. I
> am
> creating a master table in Access of archived Excel files, each file has
> multiple worksheets. Is there a need to use both SQL and VBA to
> accomplished
> the import. TIA



 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      19th Mar 2009
I tried to do this a few days ago; never figured it out. How do you "read"
the worksheet names from the Excel files?

I tried this, but it didn't work:
For i = 1 To Workbooks(MyWorkBook).Sheets.Count
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
strTablename, strPath & strFile, blnHasFieldNames
Next i

Here is the code that I was working with (this imported the first sheet in
each Excel file):
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

Again, it reads the first sheet, and only the first sheet, in each Excel file.
How can this be modified to read multiple sheets in each Excel file, and
also loop through all the Excel files in a folder?

Thanks,
Ryan---
--
RyGuy--
If the post was helpful, please click the ''Yes'' button to indicate such!


"Ken Snell MVP" wrote:

> Do you know the names of the worksheets in the files? Or do you have to
> "read" the worksheet names from the EXCEL files?
>
> If the former is true, you can use the code at this web page as a starting
> point. Just add another loop or extra steps for the various worksheets.
> Import Data from All EXCEL Files in a single Folder via TransferSpreadsheet
> http://www.accessmvp.com/KDSnell/EXC...ImpFolderFiles
> --
>
> Ken Snell
> <MS ACCESS MVP>
> http://www.accessmvp.com/KDSnell/
>
>
> "KramerJ" <(E-Mail Removed)> wrote in message
> news:6E58A88E-0A62-42FA-9E32-(E-Mail Removed)...
> > How do I import an EXCEL FILE WITH MULTIPLE WORKSHEETS into Access 2003. I
> > am
> > creating a master table in Access of archived Excel files, each file has
> > multiple worksheets. Is there a need to use both SQL and VBA to
> > accomplished
> > the import. TIA

>
>
>

 
Reply With Quote
 
Ken Snell MVP
Guest
Posts: n/a
 
      19th Mar 2009
Reading the worksheet names from the EXCEL file involves opening the EXCEL
file, storing the worksheet names that the code reads as it loops through
the worksheets, closing the EXCEL file, then putting a loop around your
import code for the list of worksheet names.

I've got some code to do this, which I wrote a while back.... let me find
it, and I'll post an example on my website. I've been meaning to do this for
a while, and I think I've got some time tonite to do that...so, I will!

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


"ryguy7272" <(E-Mail Removed)> wrote in message
news80BF75C-C020-44F1-AAE1-(E-Mail Removed)...
>I tried to do this a few days ago; never figured it out. How do you "read"
> the worksheet names from the Excel files?
>
> I tried this, but it didn't work:
> For i = 1 To Workbooks(MyWorkBook).Sheets.Count
> DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
> strTablename, strPath & strFile, blnHasFieldNames
> Next i
>
> Here is the code that I was working with (this imported the first sheet in
> each Excel file):
> 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
>
> Again, it reads the first sheet, and only the first sheet, in each Excel
> file.
> How can this be modified to read multiple sheets in each Excel file, and
> also loop through all the Excel files in a folder?
>
> Thanks,
> Ryan---
> --
> RyGuy--
> If the post was helpful, please click the ''Yes'' button to indicate such!
>
>
> "Ken Snell MVP" wrote:
>
>> Do you know the names of the worksheets in the files? Or do you have to
>> "read" the worksheet names from the EXCEL files?
>>
>> If the former is true, you can use the code at this web page as a
>> starting
>> point. Just add another loop or extra steps for the various worksheets.
>> Import Data from All EXCEL Files in a single Folder via
>> TransferSpreadsheet
>> http://www.accessmvp.com/KDSnell/EXC...ImpFolderFiles
>> --
>>
>> Ken Snell
>> <MS ACCESS MVP>
>> http://www.accessmvp.com/KDSnell/
>>
>>
>> "KramerJ" <(E-Mail Removed)> wrote in message
>> news:6E58A88E-0A62-42FA-9E32-(E-Mail Removed)...
>> > How do I import an EXCEL FILE WITH MULTIPLE WORKSHEETS into Access
>> > 2003. I
>> > am
>> > creating a master table in Access of archived Excel files, each file
>> > has
>> > multiple worksheets. Is there a need to use both SQL and VBA to
>> > accomplished
>> > the import. TIA

>>
>>
>>



 
Reply With Quote
 
Ken Snell MVP
Guest
Posts: n/a
 
      19th Mar 2009
OK here it is:

Import Data from All Worksheets in a single EXCEL File via
TransferSpreadsheet
http://www.accessmvp.com/KDSnell/EXC...m#ImpAllWkshts

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


"ryguy7272" <(E-Mail Removed)> wrote in message
news80BF75C-C020-44F1-AAE1-(E-Mail Removed)...
>I tried to do this a few days ago; never figured it out. How do you "read"
> the worksheet names from the Excel files?
>
> I tried this, but it didn't work:
> For i = 1 To Workbooks(MyWorkBook).Sheets.Count
> DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
> strTablename, strPath & strFile, blnHasFieldNames
> Next i
>
> Here is the code that I was working with (this imported the first sheet in
> each Excel file):
> 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
>
> Again, it reads the first sheet, and only the first sheet, in each Excel
> file.
> How can this be modified to read multiple sheets in each Excel file, and
> also loop through all the Excel files in a folder?
>
> Thanks,
> Ryan---
> --
> RyGuy--
> If the post was helpful, please click the ''Yes'' button to indicate such!
>
>
> "Ken Snell MVP" wrote:
>
>> Do you know the names of the worksheets in the files? Or do you have to
>> "read" the worksheet names from the EXCEL files?
>>
>> If the former is true, you can use the code at this web page as a
>> starting
>> point. Just add another loop or extra steps for the various worksheets.
>> Import Data from All EXCEL Files in a single Folder via
>> TransferSpreadsheet
>> http://www.accessmvp.com/KDSnell/EXC...ImpFolderFiles
>> --
>>
>> Ken Snell
>> <MS ACCESS MVP>
>> http://www.accessmvp.com/KDSnell/
>>
>>
>> "KramerJ" <(E-Mail Removed)> wrote in message
>> news:6E58A88E-0A62-42FA-9E32-(E-Mail Removed)...
>> > How do I import an EXCEL FILE WITH MULTIPLE WORKSHEETS into Access
>> > 2003. I
>> > am
>> > creating a master table in Access of archived Excel files, each file
>> > has
>> > multiple worksheets. Is there a need to use both SQL and VBA to
>> > accomplished
>> > the import. TIA

>>
>>
>>



 
Reply With Quote
 
Ken Snell MVP
Guest
Posts: n/a
 
      19th Mar 2009
Slight change in title, and an additional example:

Import Data from All Worksheets in a single EXCEL File into One Table via
TransferSpreadsheet
http://www.accessmvp.com/KDSnell/EXC...m#ImpAllWkshts


Import Data from All Worksheets in a single EXCEL File into Separate Tables
via TransferSpreadsheet
http://www.accessmvp.com/KDSnell/EXC...pAllWktsSepTbl

--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


"Ken Snell MVP" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> OK here it is:
>
> Import Data from All Worksheets in a single EXCEL File via
> TransferSpreadsheet
> http://www.accessmvp.com/KDSnell/EXC...m#ImpAllWkshts
>
> --
>
> Ken Snell
> <MS ACCESS MVP>
> http://www.accessmvp.com/KDSnell/
>
>
> "ryguy7272" <(E-Mail Removed)> wrote in message
> news80BF75C-C020-44F1-AAE1-(E-Mail Removed)...
>>I tried to do this a few days ago; never figured it out. How do you
>>"read"
>> the worksheet names from the Excel files?
>>
>> I tried this, but it didn't work:
>> For i = 1 To Workbooks(MyWorkBook).Sheets.Count
>> DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel9, _
>> strTablename, strPath & strFile, blnHasFieldNames
>> Next i
>>
>> Here is the code that I was working with (this imported the first sheet
>> in
>> each Excel file):
>> 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
>>
>> Again, it reads the first sheet, and only the first sheet, in each Excel
>> file.
>> How can this be modified to read multiple sheets in each Excel file, and
>> also loop through all the Excel files in a folder?
>>
>> Thanks,
>> Ryan---
>> --
>> RyGuy--
>> If the post was helpful, please click the ''Yes'' button to indicate
>> such!
>>
>>
>> "Ken Snell MVP" wrote:
>>
>>> Do you know the names of the worksheets in the files? Or do you have to
>>> "read" the worksheet names from the EXCEL files?
>>>
>>> If the former is true, you can use the code at this web page as a
>>> starting
>>> point. Just add another loop or extra steps for the various worksheets.
>>> Import Data from All EXCEL Files in a single Folder via
>>> TransferSpreadsheet
>>> http://www.accessmvp.com/KDSnell/EXC...ImpFolderFiles
>>> --
>>>
>>> Ken Snell
>>> <MS ACCESS MVP>
>>> http://www.accessmvp.com/KDSnell/
>>>
>>>
>>> "KramerJ" <(E-Mail Removed)> wrote in message
>>> news:6E58A88E-0A62-42FA-9E32-(E-Mail Removed)...
>>> > How do I import an EXCEL FILE WITH MULTIPLE WORKSHEETS into Access
>>> > 2003. I
>>> > am
>>> > creating a master table in Access of archived Excel files, each file
>>> > has
>>> > multiple worksheets. Is there a need to use both SQL and VBA to
>>> > accomplished
>>> > the import. TIA
>>>
>>>
>>>

>
>



 
Reply With Quote
 
ryguy7272
Guest
Posts: n/a
 
      19th Mar 2009
Thanks for the code Ken! Amazing, just amazing! I looked at your site a few
times before, but didn’t see that code there. Is it a recent addition to
your site?

You may, or may not, know about this link:
http://www.rondebruin.nl/copy2.htm

That is a great way to get data from all Excel sheets, in one workbook, into
a single sheet, which, then, is quite easy to import into Access. So,
anyway, just wanted to share with you, and others out there reading this.

Thanks again!!
Ryan---

 
Reply With Quote
 
Ken Snell MVP
Guest
Posts: n/a
 
      19th Mar 2009
That code is new to the site; put it up there last night. So it's no
surprise that you hadn't seen it before < g >.

Thanks for link to Ron's site.
--

Ken Snell
<MS ACCESS MVP>
http://www.accessmvp.com/KDSnell/


"ryguy7272" <(E-Mail Removed)> wrote in message
news:04E78DB2-8110-4539-95D6-(E-Mail Removed)...
> Thanks for the code Ken! Amazing, just amazing! I looked at your site a
> few
> times before, but didn't see that code there. Is it a recent addition to
> your site?
>
> You may, or may not, know about this link:
> http://www.rondebruin.nl/copy2.htm
>
> That is a great way to get data from all Excel sheets, in one workbook,
> into
> a single sheet, which, then, is quite easy to import into Access. So,
> anyway, just wanted to share with you, and others out there reading this.
>
> Thanks again!!
> Ryan---
>



 
Reply With Quote
 
New Member
Join Date: Mar 2012
Posts: 1
 
      13th Mar 2012
If you dont want to do this using any kind of program (manually).

Import the Excel into a SQL server blank database and then Export it to MS Acess.

You can do this in SQL Management studio. Right click on blank database-> select Task, and select Imort/Export.
 
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
How 2 import Excel file w/ multiple worksheets ??? akm Microsoft Excel Misc 1 1st Oct 2009 10:01 PM
Access import Excel - multiple Worksheets from multiple Workbooks =?Utf-8?B?SW5PdmVySGVhZA==?= Microsoft Access External Data 1 21st Feb 2007 08:32 PM
Re: Creating a .csv file that will import to multiple worksheets NickHK Microsoft Excel Programming 1 4th Jan 2007 01:45 AM
Import multiple excel worksheets at once ~ please help =?Utf-8?B?amRydWJpbnM3NQ==?= Microsoft Access External Data 1 1st Dec 2005 10:31 PM
Can a macro import multiple Excel worksheets =?Utf-8?B?TVJvYmVydHM=?= Microsoft Access Macros 2 1st Aug 2005 08:11 PM


Features
 

Advertising
 

Newsgroups
 


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