none
Using Array() function with Shapes..Select RRS feed

  • Question

  • I' am trying to dynamically select some shapes.

    I have some code that works well to yield a string that is made up of the Index of the shapes I want to select.  

    Normally, to select several shapes at once by using their Index number you can do:

    ActiveDocument.Shapes.Range(Array(21, 22, 63, 64)).Select
    

    As I said, the codes yields a string as follows:

    ArrList = "21,22,63,64"

    I am trying to use ArrList with the Array function and I cannot get it to work.

    This works:

    Dim A As Variant
    A = Array(21, 22, 63, 64)
    
    ActiveDocument.Shapes.Range(A).Select

    But this does not:

    Dim A As Variant
    A = Array(Split(ArrList, ","))
    
    ActiveDocument.Shapes.Range(A).Select

    I get an Invalid Procedure or Call error.

    Maybe it has to do with the fact that 

    A = Array(Split(ArrList, ","))

    seems to yield a two dimensional array instead of the uni-dimensional array that is needed.

    How can I get "ArrList" to provide the Index number to Array() so that I can select just those shapes?

    Thank you.

    Friday, April 22, 2016 6:36 PM

Answers

  • >>>How can I get "ArrList" to provide the Index number to Array() so that I can select just those shapes?

    According to your description, I have made a sample and reproduced this issue, so I suggest that you could modify your codes like below:
    ArrList = "21,22,63,64"
    
      A = Split(ArrList, ",")
    
      Dim arr() As Variant
    
      ReDim arr(UBound(A))
    
      For i = 0 To UBound(A)
        arr(i) = CInt(A(i))
      Next i
          
    ActiveDocument.Shapes.Range(arr).Select


    Monday, April 25, 2016 4:34 AM

All replies

  • >>>How can I get "ArrList" to provide the Index number to Array() so that I can select just those shapes?

    According to your description, I have made a sample and reproduced this issue, so I suggest that you could modify your codes like below:
    ArrList = "21,22,63,64"
    
      A = Split(ArrList, ",")
    
      Dim arr() As Variant
    
      ReDim arr(UBound(A))
    
      For i = 0 To UBound(A)
        arr(i) = CInt(A(i))
      Next i
          
    ActiveDocument.Shapes.Range(arr).Select


    Monday, April 25, 2016 4:34 AM
  • Hello David,

    Thanks, that did it:

      For i = 0 To UBound(A)
        arr(i) = CInt(A(i))
      Next i


    I must have tried two dozen ways to create the array I needed to pass to Range(...).Select, including something similar to what you suggested, except it never occurred to me to convert to Integer. I had tried converting to Variant or String, but not Integer.

    Thanks!

    Monday, April 25, 2016 2:36 PM
  • Hi, Jean-Guy Marcil

    You are welcome, I am glad to hear that you have resolved your issue.
    Tuesday, April 26, 2016 7:51 AM