Novice question: I cannot get the immediate window to work

R

Rodby

I am trying to learn VBA from a STEP BY STEP written by Reed Jacobson.
He encourages using the Immediate Window because he claims you can see the
progress as you code.
I am copying his code verbatim. For example, in the current practice, I have
the following Macro shell;

Sub PivotSet Style()
Dim pt as Pivottable
Dim ts as Tablestyle
Set pt=ActiveCell.Pivottable
End sub

I initialize this by pressing F8 three times, and then I type the following
in the immediate window:
Set
ts=ActiveWorkbook.Tablestyles("PivotStyleDark2").Duplicate("NewPivotStyle")
pt.Tablestyle2=ts.Name

(Note: the "Set ts= ActiveWorkbook..." statement above, is all on one line
in the immediate window)

When I get to the last line I get an "Object Required" error message.

I've checked the code and the instructions, and I cannot see anything
different from what I have copied.

What am I doing wrong?
 
R

Rodby

Joel, thank you!

to be fair to the author I copied this from, there was a pivot table on an
active sheet. I do not know if I had actually was in a cell in the table.

Is there something about the immediate window that I am missing? I rarely
get it to work, and it often gives me "undefined" type messages.
 
R

Rodby

Joel, thanks again!

I think I will be back for more as I get further along.

I find the help routines in Excel VBA almost worthless.

It is though you go to a restaurant and you see the menu, but you don't know
what "medium rare" means, or what "side items" mean, and there is
nothing/nobody to help you find out.

Anyway, thanks for the tips!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top