C
Chey
I am using a code and I am getting the error compile error
Set xlw = xlx.Workbooks.Open("H:\shared\Travel-DPA\TA and TERF DHSS Linked
MASTER.xls"), , True
this is the path name to my file.
does it have to be on my hard drive????
here is the rest of my code
Dim lngColumn As Long
Dim xlx As Object, xlw As Object, xls As Object, xlc As Object
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set xlx = CreateObject("Excel.Application")
xlx.Visible = True
Set xlw = xlx.Workbooks.Open("H:\shared\Travel-DPA\TA and TERF DHSS Linked
MASTER.xls"), , True
Set xls = xlw.Worksheets("TA")
Set xlc = xls.Range("A1")
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("QueryName", dbOpenDynaset)
If rst.EOF = False And rst.BOF = False Then
rst.MoveFirst
' write header cells
For lngColumn = 0 To rst.Fields.Count - 1
xlc.Offset(0, lngColumn).Value = rst.Fields(lngColumn).name
Next lngColumn
Set xlc = xlc.Offset(1, 0)
Do While rst.EOF = False
' write data cells
For lngColumn = 0 To rst.Fields.Count - 1
xlc.Offset(0, lngColumn).Value = rst.Fields(lngColumn).Value
Next lngColumn
rst.MoveNext
Set xlc = xlc.Offset(1, 0)
Loop
End If
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
Set xlc = Nothing
Set xls = Nothing
xlw.Close False
Set xlw = Nothing
xlx.Quit
Set xlx = Nothing
End Sub
Thanks
Set xlw = xlx.Workbooks.Open("H:\shared\Travel-DPA\TA and TERF DHSS Linked
MASTER.xls"), , True
this is the path name to my file.
does it have to be on my hard drive????
here is the rest of my code
Dim lngColumn As Long
Dim xlx As Object, xlw As Object, xls As Object, xlc As Object
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set xlx = CreateObject("Excel.Application")
xlx.Visible = True
Set xlw = xlx.Workbooks.Open("H:\shared\Travel-DPA\TA and TERF DHSS Linked
MASTER.xls"), , True
Set xls = xlw.Worksheets("TA")
Set xlc = xls.Range("A1")
Set dbs = CurrentDb()
Set rst = dbs.OpenRecordset("QueryName", dbOpenDynaset)
If rst.EOF = False And rst.BOF = False Then
rst.MoveFirst
' write header cells
For lngColumn = 0 To rst.Fields.Count - 1
xlc.Offset(0, lngColumn).Value = rst.Fields(lngColumn).name
Next lngColumn
Set xlc = xlc.Offset(1, 0)
Do While rst.EOF = False
' write data cells
For lngColumn = 0 To rst.Fields.Count - 1
xlc.Offset(0, lngColumn).Value = rst.Fields(lngColumn).Value
Next lngColumn
rst.MoveNext
Set xlc = xlc.Offset(1, 0)
Loop
End If
rst.Close
Set rst = Nothing
dbs.Close
Set dbs = Nothing
Set xlc = Nothing
Set xls = Nothing
xlw.Close False
Set xlw = Nothing
xlx.Quit
Set xlx = Nothing
End Sub
Thanks