Hi Bernd
I did look up the messages but I think part of my
question is still unanswered. Maybe I should have been
more specific.
I have 2 worksheets in my file that will always been
named 'tbl_A' & 'tbl_B'.
I am looking to write a code in VB that will
automatically import these 2 worksheets into the 2 tables
in access also name 'tbl_A' & 'tbl_B'. However, I do not
have a specific range set (the number of columns in the
excel worksheets will always be the same but the number
of rows may vary).
Below is as far as I've managed to go on this:
Dim x As Integer
Dim filetoOpen As String
Standardizedfile = ActiveWorkbook.Name
'Find Standardized file
MsgBox "Please specify the location of the
Standardized File", vbOKOnly, "Locate File"
filetoOpen = Application.GetOpenFilename("Excel Files
(*.xls), *.xls", , _
"Please select the Standardized.xls file to link to")
If filetoOpen <> "" Then
FileName = Right(filetoOpen, Len(filetoOpen) -
InStrRev(filetoOpen, "\"))
On Error Resume Next
If IsError(Windows(FileName).Activate) Then
Workbooks.Open filetoOpen
Else
Windows(FileName).Activate
End If
DoCmd.TransferSpreadsheet , acImport,
acSpreadsheetTypeExcel8, XLapp.Standardizedfile.Sheets
(tbl_A), XLFile, True, XLSheet _
DoCmd.TransferSpreadsheet , acImport,
acSpreadsheetTypeExcel8, XLapp.Standardizedfile.Sheets
(tbl_B), XLFile, True, XLSheet _
End Sub
Any suggestions?
-----Original Message-----
Hi Leo,
Anotherone had a similar question which I have answered -
try searching for FILNIGERIA in the General Questions
newsgroup. There are several posts concerning this.
In addition i wrote some comments below.
--
HTH
Bernd
If you want to browse through your drives, check:
First item in the 'API' section at the AccessWeb ...
www.mvps.org/access
If you want to have the user enter drive, file etc
XLFile = InputBox("Please enter Filename incl. Directories and drive : ")
With the following code you get the number of sheets in your Excel file :
SheetCount = XLapp.ActiveWorkbook.Sheets.Count
The names of the sheets you'll get with :
For n = 1 to SheetCount
SheetName(n) = XLapp.ActiveWorkbook.Sheets(n).Name
MessageText = MessageText & n & ".) " SheetName(n) & " "
Next n
XLapp needs to be defined first :
Dim XLapp As Object
and
Set XLapp = GetObject(, "Excel.Application")
With
SheetNumber = InputBox (MessageText)
you can ask the User to enter a number
It could be possible that there is something in Access
to get a list of possible tables - unfortunately don't
know at the moment - don't have Access at home ;-)
But you could use of course the InputBox as well. So
that the User can enter the table.
TableName = InputBox ("Table ? ")
At the end you can use the
DoCmd.TransferSpreadsheet acImport,
acSpreadsheetTypeExcel8, TableName, XLFile, True,
XLapp.ActiveWorkbook.Sheets(SheetNumber).Name & "!
a1..zz1000"