1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Run-time Error '91':Object Variable or With block variable not set When Runin

Discussion in 'Business Applications' started by moonbug, Sep 25, 2012.

Thread Status:
Not open for further replies.
  1. moonbug

    moonbug Thread Starter

    Joined:
    Sep 25, 2012
    Messages:
    2
    I recorded a macro and run the same code below which works.
    So, I saved it as an xla add-in and ran the same code. It creates the pivot table
    but I get the error below when it is about to fill the data for the row

    Run-time Error '91':Object Variable or With block variable not set

    This error on the procedure Sub Test() below occurs at line ActiveWorkbook.PivotTableWizard.
    Any suggestion on how to fix this error?

    Sub Test()

    ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
    "print_logs!R3C1:R6C40").CreatePivotTable TableDestination:="", TableName:= _
    "PivotTable1", DefaultVersion:=xlPivotTableVersion10

    ********* Error Message shows when executing line below

    ActiveWorkbook.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
    ActiveSheet.Cells(3, 1).Select
    ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:="Comment", _
    ColumnFields:="Paper Size"
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Total Pages").Orientation _
    = xlDataField


    End Sub
     
  2. moonbug

    moonbug Thread Starter

    Joined:
    Sep 25, 2012
    Messages:
    2
    change ActiveSheet to ActiveWorkbook.ActiveSheet
     
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1070364

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice