How to create drop down menu for freeform objects?

D

DORI

Dear all,
I have 10 freeform objects or shapes that I have created by drawing tool (PC
Excel 2003) and have grouped them (Group1...Group10).
I am wondering if it is possible to create a drop-down menu which shows
miniature shapes of the Group1...Group10 instead of using text. I want the
operator be able to see all the shapes and then decide which one to click to
choose from.
I know this can be done with text but I need to have this menu with actual
shapes as it is difficult to convert the visual graphic to some descriptive
text in my project.
Thanks for any comments.
DORI
 
K

Ken Johnson

Hi DORI,

I'm reasonably sure that can't be done.

You could however make your 10 miniatures then position them close to
the cell where you were considering having the drop down.
Each of the miniatures can be assigned to the same macro. This macro
could detect which miniature was clicked.
If all the miniatures are normally not visible, you could use a
Worksheet_SelectionChange Event Sub to make them all visible when the
user clicks in the cell about which they are arranged.
After they become visible the user can click on their choice. This runs
the macro that could then place an appropriate value into the cell as
well as remove the miniatures from view.

Does this sound like a suitable alternative?

Ken Johnson
 
K

Ken Johnson

Another possibility is a user form with pictures of the 10 groups and
an option button next to each.

Ken Johnson
 
D

DORI

Hi Ken,
I am glad that you noticed my posting.
Yes, that works for my project. Would it be possible to hide all the
miniatures once one of them has been clicked on?
Thanks for your help.
DORI
 
K

Ken Johnson

Hi DORI,

I've setup a sheet with four groups that I have named Group 01~, Group
02~, Group 03~ and Group 04~ (you could extend it up to Group 99~).

I copied each group then did a paste special Picture (Enhanced
metafile). I then reduced each copy's size to make the four miniatures.
I renamed them Group 01~~, Group 02~~, Group 03~~ and Group 04~~.

With my first attempt I just copied each group and did an ordinary
paste for each miniature.
When I assigned these miniatures to my macro they failed to work
consistently. With office 2003 they have changed the way grouped shapes
respond when clicked, so I have had to use paste special to get the
miniatures to work consistently as macro buttons.

I then set up the following Worksheet_SelectionChange Event Sub...

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range)
If Target.Cells(1, 1).Address = "$B$6" Then
Dim Shp As Shape
Dim logicalCanBeSeen As Boolean
For Each Shp In ActiveSheet.Shapes
If Right(Shp.Name, 2) = "~~" Then
Shp.Visible = Not (Shp.Visible)
logicalCanBeSeen = Shp.Visible
End If
Next Shp
Application.EnableEvents = False
If logicalCanBeSeen Then
With Range("B6")
.Value = "Click a Pic"
.Offset(-5, -1).Select
End With
Else: With Range("B6")
.Value = "Click Here"
.Offset(-5, -1).Select
End With
End If
Application.EnableEvents = True
End If
End Sub

When the user clicks in B6 the selection change triggers the macro
which looks for shapes with name ending in "~~", ie the miniatures.
When each is found, its visibility is toggled. This brings all the
miniatures into view (I have positioned them around B6.
Also, the text in B6 is changed. If the Miniatures are visible B6 will
show "Click a Pic", if invisible it will show "Click Here".
The code then selects A1. This has to be done, otherwise the next time
the user clicks in B6 it won't result in a selection change and the
code will not be executed. However, when coding a selection change
within a Worksheet_SelectionChange Event Sub, you must make sure the
code makes Application.EnableEvents = False before it then True after
it. If coding is not set up this way then it ends up in an endless
loop. You've experienced this before.

Each of the miniatures has been assigned to the following standard
macro.
(To assign a shape to a macro =>Right click miniature>select "assign
macro">select the macro from the list of macro names)

Public Sub GetUsersChoice()
Dim strUsersChoice As String
Dim Shp As Shape
Dim ncTildeGroups As New Collection
Dim shpChosen As Shape
Dim I As Integer
strUsersChoice = Application.Caller
Range("B6").Select
For Each Shp In ActiveSheet.Shapes
If Right(Shp.Name, 1) = "~" And Right(Shp.Name, 2) <> "~~" Then
ncTildeGroups.Add Item:=Shp
End If
Next Shp
For Each Shp In ncTildeGroups
If Shp.Name = Left(strUsersChoice, Len(strUsersChoice) - 1) Then
Set shpChosen = ActiveSheet.Shapes(Left(strUsersChoice,
Len(strUsersChoice) - 1))
Shp.Visible = True
Else: Shp.Visible = False
End If
Next Shp
Do While I < 360
I = I + 1
shpChosen.IncrementRotation 1
Calculate
Loop
End Sub

This macro is run after the user clicks on one of the miniatures.
The miniature that was clicked is identified by Application.Caller,
which returns the clicked miniature's name.
So, if the user clicked the miniature named Group 01~~, then
Application.Caller returns the string "Group 01~~".
Once the clicked miniature button has been determined the code then
selects B6, triggering the Worksheet_SelectionChange Events Sub, which
makes the miniatures invisible and changes the text in B6 to "Click
Here"

Now the code in the GetUsersChoice macro scans the sheet for the Groups
whose names end with ~ but not ~~ and adds those to a new collection
called ncTildeGroups.
The shapes in this collection are then searched for the one whose name
is the same as the clicked Miniature's name, ignoring the last ~. That
group is rendered visible, while the rest in that collection are
rendered invisible. I then show off a bit and make the visible shape do
a 360 degree rotation (Just for fun!).

I will email the sheet so that you have a better idea of how it works.

If you have any problems adapting this to your sheet don't hesitate
to email the sheet to me, along with any useful info, and I will do
what I can.

Ken Johnson
 
D

DORI

Hi Ken,
Thank you so much for such a clear explanation and detailed codes. I will
let you know how it goes.
DORI
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top