Please I need help with importing from excel

A

Al

I am using the following line of code from withing access
to import from excel:

DoCmd.TransferSpreadsheet acImport, 8, Me![NewTableName],
Me![DirName], True, Me![SheetRangeName]

Me![DirName] = the file path
Me![SheetRangeName] = A named range that the user has to
enter manually.

How can I substitute the "Me![SheetRangeName]" for
whatever populated range in excel automatically?
can someone help?
thanks
Al
 
A

Alex Ivanov

This may help...

Function GetExcelPopulatedRange(WorkBookPath As String)
Dim xl As Object
Set xl = CreateObject("excel.application")
With xl.Workbooks.Open(WorkBookPath).Worksheets(1)
GetExcelPopulatedRange = .Range("$A$1:" &
..Range("$a$1").SpecialCells(11).Address).Address
End With
xl.Quit
End Function
 
A

Al

Thank you it works well.
Al
-----Original Message-----
This may help...

Function GetExcelPopulatedRange(WorkBookPath As String)
Dim xl As Object
Set xl = CreateObject("excel.application")
With xl.Workbooks.Open(WorkBookPath).Worksheets(1)
GetExcelPopulatedRange = .Range("$A$1:" &
..Range("$a$1").SpecialCells(11).Address).Address
End With
xl.Quit
End Function


--
Please reply to NG only. The email address is not monitored.

Alex.

Al said:
I am using the following line of code from withing access
to import from excel:

DoCmd.TransferSpreadsheet acImport, 8, Me![NewTableName],
Me![DirName], True, Me![SheetRangeName]

Me![DirName] = the file path
Me![SheetRangeName] = A named range that the user has to
enter manually.

How can I substitute the "Me![SheetRangeName]" for
whatever populated range in excel automatically?
can someone help?
thanks
Al


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top