udf returns array somehow invalid

martingaleh

Board Regular
Joined
Jul 18, 2011
Messages
83
I just want an array function that returns the worksheet names in an array. It says the function is invalid when I type =names() in any cell. When I just test it in a test sub, it works fine.
Code:
Function names() As String()
    Dim n As Integer
    Dim k As Integer
    n = ThisWorkbook.Worksheets.Count
    Dim x As Variant
    Dim ws As Worksheet
    Dim zcount As Integer
    Dim j() As String
    ReDim j(1 To n - 1, 1 To 1)
    zcount = 1
    For Each ws In ThisWorkbook.Worksheets
        If (ws.Name <> "Output") Then
            j(zcount, 1) = ws.Name
            zcount = zcount + 1
        End If
    Next
    names = j
    k = 1
End Function
 
None of that would make Names the default property of the Workbook object though.

The last part I suspect is slightly misleading. I think Names on its own (outside the ThisWorkbook module of a workbook) would be a shorthand for Application.Names, which is indeed "equivalent" to ActiveWorkbook.Names. Again, though, that would not make Names a default property of anything.
I see what you are saying when you say "equivalent", and I'll be the first to admit that I am not all that conversant with Object "stuff", but I was always under the impression that if you used a property by itself and it worked the same as using it with a specific object reference, that that property was a default property of that object. Hence, when Names.Parent.Name printed the active workbook name, I figured Names was the default property of the workbook object.
 
Last edited:
Upvote 0

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
I was always under the impression that if you used a property by itself and it worked the same as using it with a specific object reference, that that property was a default property of that object

Wrong way round. ;) If you can use the object without specifying the property - like Range("A1") instead of Range("A1").Value - then the property is the default.
 
Upvote 0
If you can use the object without specifying the property - like Range("A1") instead of Range("A1").Value - then the property is the default.

Is this the only way to find out the default property of an object?
See my post 10

M.
 
Last edited:
Upvote 0
It's flagged in the object browser with a blue circle. Unfortunately in most cases the default is a hidden _Default property!
 
Upvote 0
Wrong way round. ;) If you can use the object without specifying the property - like Range("A1") instead of Range("A1").Value - then the property is the default.
Ohhhh, now I get it. :oops: See, I told you I was not "all that conversant with this Object 'stuff'".
 
Last edited:
Upvote 0
It's flagged in the object browser with a blue circle. Unfortunately in most cases the default is a hidden _Default property!

hmm...for sure i'm missing something obvious but using the Object Browser
Class
...
...
Range
...

Looking at Members of Range i can't see a blue circle or anything similar near Value :confused:

M.
 
Upvote 0
Show hidden members then you'll see the _Default property, which has the same signature as Value
 
Upvote 0
Ah! but selecting Value i can see
Property Value([RangeValueDataType])
Member of Excel.Range

It seems it's the only property with this text (bold).
Does it indicate the default property?

M.
 
Last edited:
Upvote 0
No, that's just an optional argument.
 
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,181
Members
449,071
Latest member
cdnMech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top