View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Jim Cone Jim Cone is offline
external usenet poster
 
Posts: 3,290
Default Object Variable Not Set Error on Selection object

Jean,

Not quite sure what you are trying to do with all of the cuts
and selects. Some general suggestions that should help...

Don't select anything (with rare exceptions).

Use range objects, do not use selection or activesheet or activecell ...
Set rngToUse = wksNew.Columns(sColRange)

If you don't use a range object then qualify it with the parent object ...
wksNew.Columns("L:L")

Remember that clearing a range will empty the clipboard.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"Jean" wrote in message ...
Hi,
I am export some MS ACCESS 2003 Query records onto an Excel Spread Sheet.
One section of the code is select a range of cells and move the these cells
by the columns into another location. I am using "SELECTION". Please see
below codes. The problem is I can only run the module (written in MS ACCESS)
once without error. After the 1st time, I closed the Excel spreadsheet
(genereated by the 1st run), call the module again, I would run into this
error when it hit the "Selection" object. It would error at
"Selection.Clear". But if I closed MS ACCESS and restart, I can run the
report without error.

'Error: Object Variable Not Set or With Object Variable Not Set

Set rngCurr = wksNew.Range(wksNew.Cells(6, 9), _
wksNew.Cells(7 + rstProjects.RecordCount,
rstProjects.Fields.Count - 2))

'wksNew.Columns(sColRange).Cut
'wksNew.Columns("I:L").Cut
'rngCurr.Columns.Select
Selection.Clear
rngCurr.Select
Selection.EntireColumn.Select
appExcel.CutCopyMode = False
Selection.Cut

'ActiveWindow.LargeScroll ToRight:=-2
Columns("C:C").Select
Selection.Insert Shift:=xlToRight
Set rngCurr = Nothing
Please help...
Thanks
Jean