Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default Pivot Table - Object variable or with block variable not set?

Is there really an ActiveSheet?

--
George Nicholson

Remove 'Junk' from return address.


"Darrell Wesley" wrote in message
...
I have a visual basic application that creates a Excel spreadsheet and

then creates a pivot table from the data found on Sheet1. The first pass
thru the code everything works fine but if I send it thru this section of
code again without closing the application I get an:

Run_Time error '91'

Object variable or with block variable not set

The code for the pivot table creation is as follows:

With ObjExcel
.ActiveWorkbook.PivotCaches.Add(SourceType:=xlData base, SourceData:= _
"Sheet1!R1C1:R" & row1 & "C20").CreatePivotTable

TableDestination:="", TableName:= _
"PivotTable1"
.ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3,

1)
.ActiveSheet.Cells(3, 1).Select
With .ActiveSheet.PivotTables("PivotTable1")
.ColumnGrand = False
.RowGrand = False
.SmallGrid = False
End With
.ActiveSheet.PivotTables("PivotTable1").AddFields

RowFields:=Array("Run#", _
"WMW", "WML", "COIL HGT")
.ActiveSheet.PivotTables("PivotTable1").PivotField s("Qty").Orientation

= _
xlDataField

.ActiveSheet.PivotTables("PivotTable1").PivotField s("WML").Subtotals =

Array( _
False, False, False, False, False, False, False, False, False,

False, False, False)

.ActiveSheet.PivotTables("PivotTable1").PivotField s("WMW").Subtotals =

Array( _
False, False, False, False, False, False, False, False, False,

False, False, False)

.ActiveSheet.PivotTables("PivotTable1").PivotField s("Run#").Subtotals

= Array( _
False, False, False, False, False, False, False, False, False,

False, False, False)
.ActiveSheet.PivotTables("PivotTable1").PivotField s("Count of

Qty").Function = _
xlSum
.ActiveSheet.PivotTables("PivotTable1").PrintTitle s = True
.ActiveSheet.Name = "BOXES"
End With

The line that gets the error is

.ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)

Any ideas as to what is happening?




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 170
Default Pivot Table - Object variable or with block variable not set?

The code you provided does not contain a loop. Therefore, I assume the 1st
and 2nd pass you refer to are instigated by some other part of your program.
Since this piece of code behaves differently the 2nd time, my guess is that
the status of the workbook or worksheet changes between the 1st call and the
2nd.

If there is no active sheet when this code is called, it will fail on the
line you indicate. There may be another reason for the failure, but that is
the 1st question I would ask myself.

Stated another way: this code depends on the status of the workbook being a
specific way before it is called in order for it to work. I suspect
something about how you "send it thru this section of code again" the 2nd
time differs from the 1st and is the source of the problem. However, I
can't say that for certain.

--
George Nicholson

Remove 'Junk' from return address.


"Darrell Wesley" wrote in message
...
How would I know? Like I said the first pass through everthing works, the

second time around with no changes is when the erro shows up.

I could post the entire routine if helpfull.


----- George Nicholson wrote: -----

Is there really an ActiveSheet?

--
George Nicholson

Remove 'Junk' from return address.


"Darrell Wesley" wrote in

message
...
I have a visual basic application that creates a Excel spreadsheet

and
then creates a pivot table from the data found on Sheet1. The first

pass
thru the code everything works fine but if I send it thru this

section of
code again without closing the application I get an:
Run_Time error '91'
Object variable or with block variable not set
The code for the pivot table creation is as follows:
With ObjExcel

.ActiveWorkbook.PivotCaches.Add(SourceType:=xlData base,

SourceData:= _
"Sheet1!R1C1:R" & row1 & "C20").CreatePivotTable

TableDestination:="", TableName:= _
"PivotTable1"
.ActiveSheet.PivotTableWizard

TableDestination:=ActiveSheet.Cells(3,
1)
.ActiveSheet.Cells(3, 1).Select
With .ActiveSheet.PivotTables("PivotTable1")
.ColumnGrand = False
.RowGrand = False
.SmallGrid = False
End With
.ActiveSheet.PivotTables("PivotTable1").AddFields

RowFields:=Array("Run#", _
"WMW", "WML", "COIL HGT")

..ActiveSheet.PivotTables("PivotTable1").PivotFiel ds("Qty").Orientation
= _
xlDataField

..ActiveSheet.PivotTables("PivotTable1").PivotFiel ds("WML").Subtotals =
Array( _
False, False, False, False, False, False, False, False,

False,
False, False, False)

..ActiveSheet.PivotTables("PivotTable1").PivotFiel ds("WMW").Subtotals =
Array( _
False, False, False, False, False, False, False, False,

False,
False, False, False)

..ActiveSheet.PivotTables("PivotTable1").PivotFiel ds("Run#").Subtotals
= Array( _
False, False, False, False, False, False, False, False,

False,
False, False, False)
.ActiveSheet.PivotTables("PivotTable1").PivotField s("Count of

Qty").Function = _
xlSum
.ActiveSheet.PivotTables("PivotTable1").PrintTitle s = True
.ActiveSheet.Name = "BOXES"
End With
The line that gets the error is
.ActiveSheet.PivotTableWizard

TableDestination:=ActiveSheet.Cells(3, 1)
Any ideas as to what is happening?



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
Runtime Error '91' Object variable or With block variable not set Alec Coliver Excel Discussion (Misc queries) 2 October 24th 09 02:29 PM
object variable or with block variable not set Diego Excel Discussion (Misc queries) 1 August 9th 05 02:46 PM
Ogilvy Help :) - "Object variable or With block variable not set" Mike Taylor Excel Programming 1 December 16th 03 07:21 AM
Error 91 - Object variable with block variable not set Jim[_35_] Excel Programming 2 November 27th 03 03:34 AM
Object Variable or With Block variable not set? Chris M.[_3_] Excel Programming 3 August 26th 03 04:30 PM


All times are GMT +1. The time now is 12:15 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"