Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro to run Import wizard in Access 1

Status
Not open for further replies.

OzzieOwl

Technical User
Dec 13, 2001
45
GB
Does anyone know how to create a macro in Access to import data from an Excel spreadsheet to an existing table in Access. I would nally record the macro to get some idea, but that option does not appear to be available on Access

Any help greatly appreciated.

Martin

[bugeyed][wiggle][worm]
 
Hi MartinLymn

You can write a code and attach it to a commandbutton, here is what I did

Sub GetXLData_Click()

Dim myXL As Object, myDB As Database, myRS As Recordset

Set myDB = CurrentDb()
Set myRS = myDB.OpenRecordset("tblYourTableName")
Set myXL = CreateObject("Excel.Application")
Set myXL = GetObject("c:\myPath\GetDataXL.xls")

myXL.Application.Visible = True
myXL.Application.windows(1).Visible = True

With myRS
.AddNew
.Fields("FieldNo1") = myXL.sheets("sheet1").range("a1").Value
.Fields("FieldNo2") = myXL.sheets("sheet1").range("b1").Value
.Fields("FieldNo3") = myXL.sheets("sheet1").range("c1").Value
.Update
End With

With myXL.Application
.Save
.Quit
End With
Set myXL = Nothing

DoCmd.OpenTable "tblYourTableName"

End Sub

Hope this is of some help to you.

Regards :)

LSTAN


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top