Solved

Excel 2010: Selecting shapes by name not id when names are numbers

Posted on 2014-09-13
6
342 Views
Last Modified: 2014-09-16
My client has a worksheet with a list shape names in column A. The rest of the worksheet has varying shapes that match the names in column A. The problem is that all of his shape names are numbers from 1 to 1000. This means when I use something like: "activesheet.shapes("128").select" the shape with the id of 128 will be selected instead of the shape with the name of "128". Is there a way to select a shape based on the name only?

Below is a small snippet of code that will select each shape that exists in column A. Any way to adjust this to select shapes by the name instead of the id?

x=1
Do

activesheet.shapes(activesheet.cells(x,1)).select

x=x+1
Loop while (x<250)
0
Comment
Question by:ouestque
  • 4
6 Comments
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40320881
That does not happen when I do it.

I created several shapes and then named them with out of order numbers. The when I did this

ActiveSheet.Shapes("2").Select

Open in new window


followed by this

ActiveSheet.Shapes(2).Select

Open in new window


different shapes were selected.
0
 
LVL 46

Accepted Solution

by:
Martin Liss earned 334 total points
ID: 40320886
Oh, I see! Do this instead.

activesheet.shapes(activesheet.cells(x,1).Text).select
0
 
LVL 46

Assisted Solution

by:Martin Liss
Martin Liss earned 334 total points
ID: 40320890
You also might consider changing your loop to this


For x = 1 To 250

activesheet.shapes(activesheet.cells(x,1).Text).select

Next

Open in new window

0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 27

Assisted Solution

by:Glenn Ray
Glenn Ray earned 166 total points
ID: 40321080
As an alternate method, you could consider using the For...Each method to select all shapes in a sheet like so:
Sub Edit_Shapes()
    Dim shp As Shape
    For Each shp In ActiveSheet.Shapes
        'Test or process the shape object
        'Use shp. to control the shape object for example
        'MsgBox shp.Name
        Next shp
End Sub

Open in new window


This way, you don't have to know the names of each shape, nor do you need to know how many there are on each sheet.

Regards,
-Glenn
0
 

Author Closing Comment

by:ouestque
ID: 40325208
Awesome. Thanks!!!
0
 
LVL 46

Expert Comment

by:Martin Liss
ID: 40325382
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2014
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question