DenMiller57
Registered User.
- Local time
- Today, 09:18
- Joined
- May 3, 2006
- Messages
- 13
I cannot send to the second worksheet in Ex. The following code works great sending to sheet 1, but I get an undefined error with page 2. I have tried to use the activate method before posting. Here is the code that works. Im DOA, is that the problem?
Dim DB As Database
Dim rst As Recordset
Dim xlApp As Object
Dim xlWb As Object
Dim xlWsMel As Object
Dim xlWsERD As Object
Set DB = CurrentDb
Set rst = DB.OpenRecordset("tmp_ExportExpenses")
Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Open(ExcelExpensePath)
Set xlWsMel = xlWb.WorkSheets(1)
Set xlWsERD = xlWb.WorkSheets(2)
Set xlWsRCPT = xlWb.WorkSheets("RCPT")
' These 3 lines work great
xlWsMel.Cells(1, "C").Value = rst!Fullname
xlWsMel.Cells(1, "G").Value = rst!EABN
xlWsMel.Cells(1, "I").Value = ProcessDate
xlWsERD.Activate
' The next 3 regardless of order or value after the equal sign, do not work
xlWsERD.Cells(4, "K") = rst!Fund
xlWsERD.Cells(4, "O").Value = rst!AgreementNum
xlWsERD.Cells(6, "N").Value = "Training Division"
xlWb.Save
xlWb.Close
xlApp.Quit
' Close objects
rst.Close
DB.Close
Set rst = Nothing
Set DB = Nothing
' Release Excel references
Set xlWsMel = Nothing
Set xlWsERD = Nothing
Set xlWsRCPT = Nothing
Set xlWb = Nothing
Set xlApp = Nothing
Dim DB As Database
Dim rst As Recordset
Dim xlApp As Object
Dim xlWb As Object
Dim xlWsMel As Object
Dim xlWsERD As Object
Set DB = CurrentDb
Set rst = DB.OpenRecordset("tmp_ExportExpenses")
Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Open(ExcelExpensePath)
Set xlWsMel = xlWb.WorkSheets(1)
Set xlWsERD = xlWb.WorkSheets(2)
Set xlWsRCPT = xlWb.WorkSheets("RCPT")
' These 3 lines work great
xlWsMel.Cells(1, "C").Value = rst!Fullname
xlWsMel.Cells(1, "G").Value = rst!EABN
xlWsMel.Cells(1, "I").Value = ProcessDate
xlWsERD.Activate
' The next 3 regardless of order or value after the equal sign, do not work
xlWsERD.Cells(4, "K") = rst!Fund
xlWsERD.Cells(4, "O").Value = rst!AgreementNum
xlWsERD.Cells(6, "N").Value = "Training Division"
xlWb.Save
xlWb.Close
xlApp.Quit
' Close objects
rst.Close
DB.Close
Set rst = Nothing
Set DB = Nothing
' Release Excel references
Set xlWsMel = Nothing
Set xlWsERD = Nothing
Set xlWsRCPT = Nothing
Set xlWb = Nothing
Set xlApp = Nothing