Import Multiple Sheets from Same Workbook in Excel

chrisbrocco

Board Regular
Joined
Mar 31, 2005
Messages
82
Re: Importing from Excel problem.

Im having trouble importing a spreadsheet into access.

The sheet im trying to import has approx 15 columns, all formatted correctly, but whenever i try to import im only getting the first 2 columns.

Im using the following code to do this -
Code:
DoCmd.TransferSpreadsheet acImport, _
acSpreadsheetTypeExcel9, _
"tablename", _
"my path", _
1, _
"A1:U200"

ive tried doing the import using the wizard, and get the same results. Only the first 2 columns.

Anyone got any ideas?

Using this code how could I import in the same way but import all sheets within one book
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Not sure... I tried the following and it seems to work fine.

DoCmd.TransferSpreadsheet acImport, 8, "newtable", "c:\excel files\poolstats.xls", False, "Stats!A1:M70"

You might want to create a TransferSpreadsheet macro, test it and then convert it to VBA. Compare it's syntax to yours.
 
Upvote 0
This works great, would you know how I could make a table with all the file paths in and make the code look at each file path and import it in.
 
Upvote 0
This works great, would you know how I could make a table with all the file paths in and make the code look at each file path and import it in.

This should get you going:

Private Sub Command0_Click()
Dim db As Database
Dim rst As Recordset
Dim x
Dim path

Set db = CurrentDb()
Set rst = db.OpenRecordset("pathtable", dbOpenTable)

If rst.RecordCount > 0 Then
Do Until rst.EOF
With rst
For x = 1 To rst.RecordCount
path = rst("path")
DoCmd.TransferSpreadsheet acImport, 8, "newtable", path & "\poolstats.xls", False, "Stats!A1:M70"
.MoveNext
Next
End With
Loop
End If

End Sub


I created a form with a command button on it. and added the code to the On Click Event.

I tested this with two paths (pathtable contains two records).
It appends the spreadsheets into the same table each time you run this.

HTH
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,755
Members
449,094
Latest member
dsharae57

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top