I have a database that needs to pull data from Excel.
Specifically, my Access field should go directly to a
cell in Excel and get that value.
I'm thinking that I use some kind of VBA code to open my
Excel file and assign the cell contents to a variable
which I then use in Access. I think I can find the cell
in Excel using a named range.
I need the exact code, though.
How do I do this?
Thx.
Joe
This is a generic code for opening an EXCEL workbook in "read-only" mode,
reading the contents of a specific cell on a specific worksheet, saving that
value into a variable (VariableName), and then closing the workbook and
EXCEL down.
Dim xlsApp As Object, xlsWB As Object, xlsWS As Object, xlsRng As Object
Set xlsApp = CreateObject("Excel.Application")
Set xlsWB = xlsApp.Workbooks.Open("C:\FolderName\FileName.xls", , True)
Set xlsWS = xlsWB.Worksheets("WorkSheetName")
Set xlsRng = xlsWS.Range("A1")
VariableName = xlsRng.Value
Set xlsRng = Nothing
Set xlsWS = Nothing
xlsWB.Close False
Set xlsWB = Nothing
xlsApp.Quit
Set xlsApp = Nothing

Signature
Ken Snell
<MS ACCESS MVP>
> I have a database that needs to pull data from Excel.
>
[quoted text clipped - 13 lines]
>
> Joe
Joe6Pack - 30 Dec 2003 18:03 GMT
Ken, thanks. that helps alot.
How can I pass that variable from Excel to Access?
Joe
>-----Original Message-----
>This is a generic code for opening an EXCEL workbook in "read-only" mode,
[quoted text clipped - 34 lines]
>
>.
Ken Snell - 30 Dec 2003 19:14 GMT
The code example that I posted would be run from inside ACCESS. Thus, the
variable already in in ACCESS.

Signature
Ken Snell
<MS ACCESS MVP>
> Ken, thanks. that helps alot.
>
[quoted text clipped - 49 lines]
> >
> >.
Joe6Pack - 31 Dec 2003 15:30 GMT
Thank you. It works exactly how I want it.
Joe
>-----Original Message-----
>The code example that I posted would be run from inside ACCESS. Thus, the
[quoted text clipped - 55 lines]
>
>.