Re: Get Excel Value
- From: Tim <Tim@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 15 Jun 2005 22:32:03 -0700
Graham,
The code works great. Thanks a lot.
Tim.
"Graham Mandeno" wrote:
> Hi Tim
>
> You need to create an instance of Excel, open the required workbook file,
> open your table, add a new record, copy the required cells from the
> work*** to the table fields, save the new record, close everything, and
> clean up.
>
> This should get you going:
>
> Dim db As DAO.Database
> Dim rs As DAO.Recordset
> Dim xlApp As Excel.Application
> Dim xlWbk As Excel.Workbook
> Dim xlSht As Excel.Work***
> Set xlApp = CreateObject("Excel.Application")
> Set xlWbk = xlApp.Workbooks.Open("C:\My Documents\test.xls",
> ReadOnly:=True)
> Set xlSht = xlWbk.Worksheets("Sheet1")
> Set db = CurrentDb
> Set rs = db.OpenRecordset("MyTable")
> With rs
> .AddNew
> !Field1 = xlSht.Range("A1")
> !Field2 = xlSht.Range("B12")
> !Field3 = xlSht.Range("B1")
> !Field4 = xlSht.Range("C10")
> .Update
> .Close
> End With
> xlWbk.Close
> xlApp.Quit
> Set xlSht = Nothing
> Set xlWbk = Nothing
> Set xlApp = Nothing
> Set rs = Nothing
> Set db = Nothing
>
> You will need to add your own error handling. You will also need a
> reference to the Excel object library, or you can use "late binding" and
> declare all the xl... variables "As Object".
> --
> Good Luck!
>
> Graham Mandeno [Access MVP]
> Auckland, New Zealand
>
> "Tim" <Tim@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
> news:1CC4A091-4206-497B-A488-E7A35EFD206D@xxxxxxxxxxxxxxxx
> > Hi folks,
> >
> > I have a excel spreadsheet called "test.xls" which has a "sheet1" in it.
> > On
> > the sheet1, there has the following data.
> >
> > A1 Peter
> > B1 student
> > B12 50
> > C5 15
> >
> > I want to get those cells' value and append to a table from VBA. For
> > example:
> >
> > A1 go to Field1
> > B12 go to Field2
> > B1 go to Fie1d3
> > C5 go to Fie1d4
> >
> > Could anyone can show me how to do it?
> >
> > Thanks in advance.
> >
> > Tim.
>
>
>
.
- References:
- Get Excel Value
- From: Tim
- Re: Get Excel Value
- From: Graham Mandeno
- Get Excel Value
- Prev by Date: Re: How can I list the files in a directory and sub directory
- Next by Date: Re: VB Insert SQL with Time Format Field
- Previous by thread: Re: Get Excel Value
- Next by thread: Search fields for quote symbols
- Index(es):