"Object not set"?

B

Bob Bridges

I'm still learning about scope and visibility of objects, but
I thought I had a general handle on the concept. This
problem, though, has me stonkered:

In a sheet module, declarations section:
Public wbo

The same sheet module, the first procedure, the
first two statements:
Set wbo = Workbooks("MyWorkbook.xls")
Stns = RangeValues("Map", 2, 4)

RangeValues is in a separate module named "Common".
It starts out like this:
Function RangeValues(SheetName, RowA, ColZ)
Set wso = wbo.Worksheets(SheetName)

So we enter RangeValues with the first argument set
to "Map", and when it gets to the statement "Set
wso=wbo.Worksheets(Sheet)" I expect it to set wso to
the worksheet named "Map". Instead I get an error 91:

Run-time error '91':
Object variable or With block variable not set.

This SEEMS to say that wbo isn't properly initialized as a
workbook object. Yet just before it executes the Set statement
I can see wbo in the Watch window, with the Map sheet as one
of its properties. So is the error message talking about some
other object? Can anyone see the obvious piece I'm missing?
 
D

Dave Peterson

Check your other post.

Bob said:
I'm still learning about scope and visibility of objects, but
I thought I had a general handle on the concept. This
problem, though, has me stonkered:

In a sheet module, declarations section:
Public wbo

The same sheet module, the first procedure, the
first two statements:
Set wbo = Workbooks("MyWorkbook.xls")
Stns = RangeValues("Map", 2, 4)

RangeValues is in a separate module named "Common".
It starts out like this:
Function RangeValues(SheetName, RowA, ColZ)
Set wso = wbo.Worksheets(SheetName)

So we enter RangeValues with the first argument set
to "Map", and when it gets to the statement "Set
wso=wbo.Worksheets(Sheet)" I expect it to set wso to
the worksheet named "Map". Instead I get an error 91:

Run-time error '91':
Object variable or With block variable not set.

This SEEMS to say that wbo isn't properly initialized as a
workbook object. Yet just before it executes the Set statement
I can see wbo in the Watch window, with the Map sheet as one
of its properties. So is the error message talking about some
other object? Can anyone see the obvious piece I'm missing?
 

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