VB to select object (ie shape or button)

velohead

Board Regular
Joined
Aug 22, 2007
Messages
212
Hi All,
I have a simple test macro that provides a sheet name in a message box.
Name just happens to be a property I show.
The macro works fine, and is as follows...


Code:
Sub WS_Name()
Dim n As Integer
n = InputBox("enter sheet number")
x = Worksheets(n).Name
MsgBox x
End Sub


I wish to change the macro to look at objects not worksheets.
By objects, I mean objects such as buttons, shapes etc, i.e. those items that can be selected by using F5, Special, Objects.

There seems to be a lot of different objects, not sure what the generic name is for them, I thought it was Shapes and Shape.

So, as I am going around in circles, how would I tackle this please.

PS
Worksheet Name just happens to be the property I specified in macro 1
In macro 2, any shape property will suffice, eg Height, ID, Name, Type etc
Once this works, I can change the property.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
I'm not sure what your ultimate goal is.

Your wanting a message box to popup with what?
 
Upvote 0
I see now your wanting put into a Input Box the name of the object and then select that object.
 
Upvote 0
ultimate aim is to automatically select each 'shape' or 'button' and return via a msgbox what 'type' the object was.
 
Upvote 0
the input box was to just select 1 of 3 objects, either a workbook or object.
There were only 3 worksheets in my workbook, and only 3 'shapes' or 'buttons' on the active sheet.
 
Upvote 0
Try this:
Code:
Sub Select_All_Shapes()
    For Each Shape In ActiveSheet.Shapes
    
    ans = "Shape Name is  " & Shape.Name & "  " & "  Shape Type is  " & Shape.Type & vbNewLine & ans
    'MsgBox ans
    Next
MsgBox ans
End Sub
 
Upvote 0
Wow, that works extremely well, better than doing a msgbox for each shape.
Thank You So Much.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,170
Members
453,021
Latest member
Justyna P

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