G
Guest
I've done this before but for some reason I can't now. Here is my code to
write a recordset to Excel.
Dim conn As ADODB.Connection
Dim rst As New ADODB.Recordset
Set conn = CurrentProject.Connection
Dim xApp As Excel.Application
Dim xWkbk As Excel.Workbook
Dim xSheet As Excel.Worksheet
Set xApp = New Excel.Application
Set xWkbk = Excel.Workbooks.Add
Set xSheet = xWkbk.Worksheets(1)
rst.Open strSQL, conn, adOpenStatic, adLockReadOnly (strSQL contains a
valid query)
xSheet.Rows("1:1").Select
With xApp.Selection.Interior (this is where the error occurs)
.ColorIndex = 15
.Pattern = xlSolid
End With
I tried to add only the pertinent code. Any way this will work every other
time. I get the "Object variable or With block variable not set" Run-time
error 91.
What am I doing wrong?
Steve
write a recordset to Excel.
Dim conn As ADODB.Connection
Dim rst As New ADODB.Recordset
Set conn = CurrentProject.Connection
Dim xApp As Excel.Application
Dim xWkbk As Excel.Workbook
Dim xSheet As Excel.Worksheet
Set xApp = New Excel.Application
Set xWkbk = Excel.Workbooks.Add
Set xSheet = xWkbk.Worksheets(1)
rst.Open strSQL, conn, adOpenStatic, adLockReadOnly (strSQL contains a
valid query)
xSheet.Rows("1:1").Select
With xApp.Selection.Interior (this is where the error occurs)
.ColorIndex = 15
.Pattern = xlSolid
End With
I tried to add only the pertinent code. Any way this will work every other
time. I get the "Object variable or With block variable not set" Run-time
error 91.
What am I doing wrong?
Steve