Chimp8471
Registered User.
- Local time
- Today, 08:59
- Joined
- Mar 18, 2003
- Messages
- 353
i am currently able to import the contents of my excel spreadsheet, into my database, on a daily basis using the following code:
Option Compare Database
Option Explicit
Private Sub Form_Open(Cancel As Integer)
Dim mysheet As Object, myfield As Variant, xlApp As Object
' Set object variable equal to the OLE object.
Set xlApp = CreateObject("Excel.Application")
' Set mysheet = GetObject("c:\access2\ole_test.xls", "excel.sheet").
Set mysheet = xlApp.workbooks.Open("\\Tech02\TrainDB\Training_DB\Trainers Report.xls").Sheets(1)
' Set the Visible property of the sheet to True, save the
' sheet, and quit Microsoft Excel.
mysheet.Application.windows("Trainers Report.xls").Visible = True
mysheet.Application.activeworkbook.Save
mysheet.Application.activeworkbook.Close
xlApp.Quit
' Clear the object variable.
Set mysheet = Nothing
' Turn the Access nags off
DoCmd.SetWarnings False
' Import SpreadSheet and name the table ExcelImport
DoCmd.TransferSpreadsheet acImport, 8, "ExcelImport", _
"\\Tech02\TrainDB\Training_DB\Trainers Report.xls", False
' I use a query to then append the data to an already
' existing table. In your case you may want to delete
' it or do something else.
'Append query
DoCmd.OpenQuery "UpdateShift", acNormal, acEdit
DoCmd.OpenQuery "qry_Totals", acNormal, acEdit
' Now I delete the table that I imported cause it is no
' longer needed.
DoCmd.DeleteObject acTable, "ExcelImport"
' Turn warnings back on
DoCmd.SetWarnings True
DoCmd.Close acForm, Me.Name
End Sub
however this imports my headings aswell, is there a simple bit of code i can add to the above to avoid the headings coming across aswell
cheers
Andy
Option Compare Database
Option Explicit
Private Sub Form_Open(Cancel As Integer)
Dim mysheet As Object, myfield As Variant, xlApp As Object
' Set object variable equal to the OLE object.
Set xlApp = CreateObject("Excel.Application")
' Set mysheet = GetObject("c:\access2\ole_test.xls", "excel.sheet").
Set mysheet = xlApp.workbooks.Open("\\Tech02\TrainDB\Training_DB\Trainers Report.xls").Sheets(1)
' Set the Visible property of the sheet to True, save the
' sheet, and quit Microsoft Excel.
mysheet.Application.windows("Trainers Report.xls").Visible = True
mysheet.Application.activeworkbook.Save
mysheet.Application.activeworkbook.Close
xlApp.Quit
' Clear the object variable.
Set mysheet = Nothing
' Turn the Access nags off
DoCmd.SetWarnings False
' Import SpreadSheet and name the table ExcelImport
DoCmd.TransferSpreadsheet acImport, 8, "ExcelImport", _
"\\Tech02\TrainDB\Training_DB\Trainers Report.xls", False
' I use a query to then append the data to an already
' existing table. In your case you may want to delete
' it or do something else.
'Append query
DoCmd.OpenQuery "UpdateShift", acNormal, acEdit
DoCmd.OpenQuery "qry_Totals", acNormal, acEdit
' Now I delete the table that I imported cause it is no
' longer needed.
DoCmd.DeleteObject acTable, "ExcelImport"
' Turn warnings back on
DoCmd.SetWarnings True
DoCmd.Close acForm, Me.Name
End Sub
however this imports my headings aswell, is there a simple bit of code i can add to the above to avoid the headings coming across aswell
cheers
Andy