shape range help
Brackets do affect the the outcome of some statements.
I forget the exact details, but it something about forcing an evaluation of
the code in the brackets and effecting the ByRef/ByVal passing method.
Private Sub CommandButton1_Click()
Dim InputSample As String
InputSample = "Input"
Call ByRefEG(InputSample)
MsgBox InputSample
InputSample = "Input"
ByRefEG InputSample
MsgBox InputSample
InputSample = "Input"
ByRefEG (InputSample)
MsgBox InputSample
End Sub
Function ByRefEG(ByRef Sample As String) As String
Sample = "Output"
ByRefEG = Sample
End Function
I'm not sure if this has anything to do with your situation; looks like
Peter may be on to something with the nature of the Variant.
NickHK
egroups.com...
The wierd thing is that, if I dispense with A altogether in my test
subs and write:
Sub Test4()
Dim Stooges As ShapeRange
Set Stooges = Sheets(1).Shapes.Range(Array("Larry", "Curly", "Moe"))
Stooges.Group
End Sub
It works fine. This is wierd since the documentation on VBA's Array
function explicitly says that it returns a variant containing an array
(as opposed to an array of variants)
When I have
Dim A as Varaint
A = Array("Larry", "Curly", "Moe")
A is *exactly* a variant containing an array - in other words, it
agrees with the return type of Array() - no implicit type coercion or
anything (at least none documented).
Thus, it really does seem to be a bug in Shapes.Range() when it accepts
a variant containing an array if fed directly in from the Array
function but balks at it if the variant containing an array is in a
declared variant variable (unless, mysteriously, enclosed in
parenthesis). But - with your (and Jim's) help - the work-around is
clear, so I won't worry about it. Excel is full of wierd quirks.
Thank you for your time
-semiopen
Peter T wrote:
wrote in message
ups.com...
Peter T wrote:
If you declare -
Dim A() As Variant iso Dim A As Variant
I think you'll find you don't need to evaluate the array by enclosing
in
brackets. see the difference in Locals
You (and Jim) are right in that context. To play around with things, I
created a new spreadsheet with three rectangles named Larry, Curly and
Moe (I like giving my shapes interesting names - how would *you* like
to be refered to as Human 12 ?) and wrote the following 3 subs:
Sub Test1()
Dim Stooges As ShapeRange
Dim A() As Variant 'an array of variants
A = Array("Larry", "Curly", "Moe")
Set Stooges = Sheets(1).Shapes.Range(A) 'works fine
Stooges.Group
End Sub
Sub Test2()
Dim Stooges As ShapeRange
Dim A As Variant 'just a variant
A = Array("Larry", "Curly", "Moe")
Set Stooges = Sheets(1).Shapes.Range(A) 'throws an error!
Stooges.Group
End Sub
Sub Test3()
Dim Stooges As ShapeRange
Dim A As Variant 'just a variant
A = Array("Larry", "Curly", "Moe")
Set Stooges = Sheets(1).Shapes.Range((A)) 'the error is gone!
Stooges.Group
End Sub
It seems to be an outright bug, no? Why should A < (A) ? If you
compare Test1 with Test3, maybe there is some sort of wierd Microsoft
conservation of parenthesis law that I was unaware of.
-semiopen
Our recent posts sent at about the same time obviously crossed, but note
the
difference between
Variant() vs Variant/Variant()
Regards,
Peter T
<snip
|