Dim rs as dao.Recordset
Dim xl as object
dim wbk as object
dim sht as object
dim rs as object
set rs = currentdb.querydefs("myQueryName").openrecordset
set xl = createobject("Excel.Application")
set wbk = xl.workbooks.Add
set sht = wbk.sheets(1)
'Write the column headers
For intLoop = 1 to rs.fields.count
sht.cells(1, intLoop).Value = rs.fields(intloop-1).Name
Next
'Highlight the column headers and copy the header column
sht.Range("B1").Select
sht.Range(Selection, Selection.End(xlToRight)).Select 'this is the line that raises the error
set rng = Selection 'this is used later in the code
with rng.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.ThemeColor = xlThemeColorDark1
.TintAndShade = -0.14996795556505
.PatternTintAndShade = 0
End With
sht.Range("A2").CopyFromRecordset rs
if NOT (rs is nothing) then
rs.close
set rs = nothing
end if
'*******************
'whole bunch of additional formatting functions here
'*******************
if NOT (rng is Nothing) then set rng = nothing
if NOT (sht is nothing) then set sht = nothing
if NOT (wbk is nothing) then set wbk = nothing
if NOT (xl is nothing) then set xl = nothing
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.
Our community of experts have been thoroughly vetted for their expertise and industry experience.
The Distinguished Expert awards are presented to the top veteran and rookie experts to earn the most points in the top 50 topics.