G
Guest
I'm trying to populate data from access to excel sheet. Everything is fine
except the two errors (please see in the code below).
Could anybody help me with this?
Thanks
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim xlapp As Object
Dim xlbook As Object
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSQL)
On Error Resume Next
Set xlapp = GetObject(, "Excel.Application")
If Err Then
Set xlapp = CreateObject("Excel.Application")
End If
On Error GoTo 0
Set xlbook = xlapp.Workbooks.Add
With xlbook
..Worksheets(1).Range("A2").CopyFromRecordset rst
..Worksheets(1).Range("A1") = "Product Code"
..Worksheets(1).Range("A1").HorizontalAlignment = xlHAlignCenter ' error ???
..Worksheets(1).Range("A1").Font.Bold = True
.Worksheets(1).Range("E2:E" &
..Worksheets(1).Range("A65536").End(xlUp).Row).FormulaR1C1 = _
"=RC[-2] * RC[-1]" ' error ???
End With
except the two errors (please see in the code below).
Could anybody help me with this?
Thanks
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Dim xlapp As Object
Dim xlbook As Object
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset(strSQL)
On Error Resume Next
Set xlapp = GetObject(, "Excel.Application")
If Err Then
Set xlapp = CreateObject("Excel.Application")
End If
On Error GoTo 0
Set xlbook = xlapp.Workbooks.Add
With xlbook
..Worksheets(1).Range("A2").CopyFromRecordset rst
..Worksheets(1).Range("A1") = "Product Code"
..Worksheets(1).Range("A1").HorizontalAlignment = xlHAlignCenter ' error ???
..Worksheets(1).Range("A1").Font.Bold = True
.Worksheets(1).Range("E2:E" &
..Worksheets(1).Range("A65536").End(xlUp).Row).FormulaR1C1 = _
"=RC[-2] * RC[-1]" ' error ???
End With