Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Problem w/ Code- Error 91 @ run-time

I am trying to extract data out of Access & then copy that data on an
excel sheet to create a pivot table. My code will work on every OTHER
try, but on the even attempts I get a run-time error 91 (object or
variable not set). Here is one small section of the code that includes
the problem area:

'Create Pivot Table
'*****
Dim xlWb As Object
Dim xlWs As Object
Dim xlAp As Object


Set xlWb = Excel.Application.ActiveWorkbook
******Set xlWs = xlWb.Worksheets("Sheet3")********* THIS IS THE PROBLEM
STMT

a = xlWs.Range("A1").Address
lastcell = xlWs.Range("A1").SpecialCells(xlCellTypeLastCell). Address
MyRange = xlWs.Name & "!" & a & ":" & lastcell

With xlWb
'Add Table & cross fingers
.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=MyRange) _
.CreatePivotTable TableDestination:="", TableName:="PivotTable1"
End With

.....I actually set each of these variables (xlWb, xlWs, etc.) to
NOTHING at the end of my code (to address late binding issues). Any
ideas why that statement is creating my problem on every other
attempt????

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Problem w/ Code- Error 91 @ run-time

I would guess the second time around, Excel is closed or there is
no active workbook.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware


"dailem"
wrote in message
I am trying to extract data out of Access & then copy that data on an
excel sheet to create a pivot table. My code will work on every OTHER
try, but on the even attempts I get a run-time error 91 (object or
variable not set). Here is one small section of the code that includes
the problem area:

'Create Pivot Table
'*****
Dim xlWb As Object
Dim xlWs As Object
Dim xlAp As Object

Set xlWb = Excel.Application.ActiveWorkbook
******Set xlWs = xlWb.Worksheets("Sheet3")********* THIS IS THE PROBLEM
STMT

a = xlWs.Range("A1").Address
lastcell = xlWs.Range("A1").SpecialCells(xlCellTypeLastCell). Address
MyRange = xlWs.Name & "!" & a & ":" & lastcell

With xlWb
'Add Table & cross fingers
.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=MyRange) _
.CreatePivotTable TableDestination:="", TableName:="PivotTable1"
End With

.....I actually set each of these variables (xlWb, xlWs, etc.) to
NOTHING at the end of my code (to address late binding issues). Any
ideas why that statement is creating my problem on every other
attempt????

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
I get run time error '5' when I run this code. any sugestions? macrowriter Excel Programming 1 December 15th 05 11:32 PM
Run-time error '9' ---- Code to fix included. [email protected] Excel Programming 3 September 2nd 05 02:48 PM
run time error '424' when I run this code ravi Excel Programming 6 August 8th 05 10:21 PM
Run-time error from my code Matt Excel Programming 5 June 24th 04 03:32 AM
Code Error - Run Time Error 5 (Disable Cut, Copy & Paste) Tim[_36_] Excel Programming 4 April 23rd 04 02:53 AM


All times are GMT +1. The time now is 01:00 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"