+ Reply to Thread
Results 1 to 26 of 26

Macro that can be assigned to a shape that records selection

  1. #1
    Registered User
    Join Date
    04-08-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    57

    Macro that can be assigned to a shape that records selection

    I'm made a tree graph using shapes but would like to add some interactive features the first of which would allow the user to click on and "select" shapes. I have a working macro that will change the color of the object to indicate when it is selected but I would like to record the object name on a separate sheet when clicked. I haven't been able to make this work yet. I'm a complete novice when it comes to VBA so any advice or suggestions are appreciated!

    Thanks,
    Attached Files Attached Files

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: Macro that can be assigned to a shape that records selection

    Why're you posting this here? you already have a relevant post
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Macro that can be assigned to a shape that records selection

    Please refer to the attached and see if this is what you were trying to achieve.
    Attached Files Attached Files
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,441

    Re: Macro that can be assigned to a shape that records selection

    These 2 routines will allow you to get a reference to the shape clicked and store that information.

    Please Login or Register  to view this content.
    Assign AnyShape_Click macro to all shapes.
    This will change the colour for the shape clicked. I noticed one of the shape specific routines used different colours, if that is the case you will need to add more code to the new macro to determine what colour should be used.
    Cheers
    Andy
    www.andypope.info

  5. #5
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: Macro that can be assigned to a shape that records selection

    This works too
    Please Login or Register  to view this content.
    But it's un maintainable

  6. #6
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: Macro that can be assigned to a shape that records selection

    This is the most simple solution.
    Assign the same macro to all shapes (just one macro for any number of shapes)
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    04-08-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    57

    Re: Macro that can be assigned to a shape that records selection

    This is exactly what I'm looking for and is a huge help! I'm working with this now to customize to me needs and your help is greatly appreciated. Thanks so much!

  8. #8
    Registered User
    Join Date
    04-08-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    57

    Re: Macro that can be assigned to a shape that records selection

    This forum never ceases to amaze and humble me! Thanks everyone for the help, the solution for the active shape fill is much more elegant than my "calling a new macro for each shape"! Couple of follow up questions...

    I would eventually like to use a hex code or decimal code for the fill color. When I try to change this in the macro i "break" it so it will default to the color I've entered but will not change on click. Any advice?

    Also, I'm using the three colors to to indicate three states: available to select, selected, & not available to select. Eventually I'd like to add the logic so a shape that has already been selected or is "not available to select" can not be clicked... but that can come later. Right now I'm working on adding the function of removing the active shape name from the record on sheet2 on a subsequent click.

    Again, any suggestions are welcome; thanks again!

  9. #9
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: Macro that can be assigned to a shape that records selection

    You and use Constants in your macros and use these.

    I have this list in my VBA project outsie the modules
    Please Login or Register  to view this content.
    And you can replace the color names for a status:
    and the option noColor to default to when it's nothing

    At the same time you can include a test in the selection shape that if it's not selectable to skip, so name one of the colors NOSELECT and you check if the shapes color is noselect then skip.
    Hope I'm making sense
    Happy coding

  10. #10
    Registered User
    Join Date
    04-08-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    57

    Re: Macro that can be assigned to a shape that records selection

    Thanks, I think replacing the colors with actual status is what I need to do going forward.

    I've tweaked the macro so shape names will only be recorded once, but I'd like to be able to remove them when "unclicked"

    I'm envisioning 3 statuses: the default color (Blue) would indicate "available to select" when clicked the fill color changes to indicate "selected".
    Current state, a 3rd click changes color again to "not available to select". (I'm planning to eventually add some logic to identify "available to select" and "not available to select" but I'm not quite there yet.

    Any advice on how to best replace colors with a status that could be tweaked to perform as described? I've attached an new test workbook that includes a logic table on "sheet3"
    Attached Files Attached Files

  11. #11
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: Macro that can be assigned to a shape that records selection

    I am assuming that this is a kind of process you want to visualize.
    The process sheet I named Process_Sheet and the Log_Sheet, well speaks for itsself
    Initial state would all shapes grey except A, D and H, these seem to be the starting points so initially Dark Blue and all others should initially be grey (not-selectable)
    If you click A then only B will become Blue and A grey following the lines (and the table , I rem=named this Admin_Sheet)
    I added a column in Admin_Sheet for the three initial shapes, a macro should be written to set these shapes to blue and the others to grey.
    I didn't do much yet but did give your sheets names and a little structure in hat sense, it's almost bedtime here so ...
    Will see/read you answer tomorrow since you still have some hours left
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    04-08-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    57

    Re: Macro that can be assigned to a shape that records selection

    Yes, that sounds great! I've made a couple of additions to the test sheet to flesh out some ideas...

    You are correct in that A,D, & H are the starting points. Your description of these starting out Dark Blue and everything else initially grey (not-selectable) is right on.

    Shape B should only become selectable once both A and D have been selected. I've added K in the reattached example to illustrate an OR feature which would make K selectable if either E or I were selected. Some shapes would also preclude others from being available. In the attached example, once G is selected, neither F or J would be able to be selected. The other feature I've added is that some shapes would be "selected" automatically-without user input, once other shapes are selected-added L in the example for this.

    Eventually I would like to be able to "hide" unavailable shapes (and their connection points) as well so they would only appear once prerequisites are met, but that's a bit down the road I think.

    Thanks so much for your help! Have a good night and please let me know if I can compensate you for your time-I always feel guilty taking advantage of everyone's help on this forum and am continually in awe of the knowledge that I gain here!
    Attached Files Attached Files
    Last edited by llomax83; 06-27-2020 at 07:33 PM. Reason: adding attachment

  13. #13
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: Macro that can be assigned to a shape that records selection

    Hi, We're here to help and point you in a direction we think is the one, every programmer or coder has his/her experience and background
    My approach:
    - Give all the shapes a descriptive name that also refers to the action Shapes A through Z
    - Connector followed by shate from -> shate to ie: ShapeA goes via ConnectorAB goes to ShapeB
    - since you have Gropued Items then name the group according to the Shape: ShapeB has GroupB
    - You have a dimond in this case with OR function so in the case of ShapeE:
    ShapeE via ConnectorEor to DiamondEK via ConnectorEorK goes to ShapeK which has GroupK

    VBA and coding is all about imagination, and your own creativity you have to tell it what to do respecting syntaxes; don't know the code then just record a macro for that specific action and see what it dis, then edit it to your needs

    This text is also in the VBA module.
    I'm not going to work it all out for you.
    Compensation is not for here, we're helping, and sometimes (I do) we get carried away and develop an entire application.
    We offer some code the OP can build on that and ask for help when he/she gest stuck
    Now that I'm retired (71) I still code Excel interfaces for a (small) living and it's good for the brain gymnastics

    Here's the file and throw your imagination, creativity at it What you need most is time (lots of it) is time and patience (troubleshooting), VBA just needs you to respect the syntax, the rest is just YOU telling it what to do.
    Think of it like reading a book, line by line and translating the actions to code; don't always select items, just name them and do your thing.
    If this is that then do the other thing els do something else but if not do whatever, etc ...
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    04-08-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    57

    Re: Macro that can be assigned to a shape that records selection

    Thanks again... my VBA knowledge is non-existent so your help is much appreciated... and needed!

    When you suggest giving all "shapes a descriptive name that also refers to the action", what do you mean by "action"? Once I have all the tools in place and working my plan is to implement them on a much larger tree graph I've already created. This graph has hundreds of objects so my plan was to name the shapes based on a six digit "key", then reference the key number in a table containing all of the object information (tech name, prerequisites, scoring information, etc). (rereading your comment I realize that you mean naming the connectors and connection point shapes?) The diamond connectors wouldn't appear in the final tree-I just added them to illustrate a unique performance characteristic of the OR function.

    I'm looking at the macro now... has gotten just a bit more complicated ! (Really like the reset button) Right now on open the 3 initial three options are blue, and will turn grey on click, but B remains grey rather than turning blue when prerequisites are met. I beleive this may have something to do with different color names on the two parts of the macro?

    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.

  15. #15
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: Macro that can be assigned to a shape that records selection

    I did nothing with the on click as yet, it was just to show what you can do and how you can approach this.
    With what you're saying, then I suggest you take someone in the arms and explain it all. You will have to give each linking line a descriptive name as well and the grouped forms hehind the shape, (like I did now)
    This will take a lot op coding hours and thinking it out.
    If the Shape's names are gong to be replaced by a six digit Key then I suggest Shape Names like Shapesixdigit and the Groupsixdigit and Connectorsixdigitfrom_sifdigitto etc.
    Hop[e it makes sense.

  16. #16
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: Macro that can be assigned to a shape that records selection

    Well, it's quite a task if you want to do it for more than that.
    The lines and all that I haven't managed (and am not going to for now)
    But the series you have here does a little of what you want.
    It will require quite some more coding to make it work for the connectors and the grouped cells as well.
    Right now it only works for the Shapes.
    In the Admin_Sheet only the columns B, C, D and E are used now
    In columns C, D and E you fill in the shape names that lead to the shape in column B
    That way the processing will work.
    The section in the original macro where you tested if gry then this if blue then that etc is skipped now. All is processed in the next macro in the module
    When it's the last Shape, (hard coded in the macro with instr function the there shapes are as one string it checks if it's the selected shape then colors it green to indicate it's finished.
    Play around with this ad throw your imagination and fantasy at it
    Attached Images Attached Images
    Attached Files Attached Files

  17. #17
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: Macro that can be assigned to a shape that records selection

    This is the next step, got a simple way (I hope to get it doen)
    This is it for starters, working out one or two more things and will explain what's required
    Attached Files Attached Files

  18. #18
    Registered User
    Join Date
    04-08-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    57

    Re: Macro that can be assigned to a shape that records selection

    Wow... I just quickly went through your responses and I'm looking forward to diving in further! My work week here is ramping up so it may be a couple of days before I can really look at it but I'm sure I will be following up with questions-thanks again!

  19. #19
    Registered User
    Join Date
    04-08-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    57

    Re: Macro that can be assigned to a shape that records selection

    Okay, stayed up WAY too late looking at this, haha. So a couple of quick questions... (also, I should mention that I would completely understand if you told me to figure it out myself at any point... I really appreciate your time and knowledge)

    On first run I got a "variable not found" error on the "FindAShape:" on the "vbBlack" variable. Played around with the color name a bit and was able to get it to run I'm looking forward to learning more about the elements and how to manipulate them!

    I started building a working version of my tree graph following your labeling suggestions and I had a question on the connector labels... Rather than labeling each connector, would it make more sense to group all of the connectors and destination shape together, then naming just the one group. (This would be most useful for techs that connect to more than one other object but also when a connector uses more than 1 shape/element to connect to its parent shape. Hope that makes sense. Do you see any issue being able to show/hide that entire group?

    Once I have a small starter version of my actual tree I'll try to change the variable names and implement the macro that you've started for me but I have a feeling that might be a slow "learning" process for me. hahaha. I'll likely need to reach out for some advice at some point!

  20. #20
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: Macro that can be assigned to a shape that records selection

    Corrected and more read the textboxes in Admin_Sheet for an explanation
    Attached Files Attached Files

  21. #21
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: Macro that can be assigned to a shape that records selection

    Ran into some minor issues and also added a textbox with some explanation which I have added here too:
    How the shapes (all) are to be named
    Shapes
    - Shape will start with Shape followed by a unique combination A,B, C, AA, AB, ZZ etc, unlimited possibilities will be identified by the VBA code.
    - The text IN the shape is to be added in the Column NEXT to corresponding Shape Name (Column L)
    This list of Shape names will be updated the moment the Refresh Button is pressed as well as all the shape names on that sheet will be listen in Column O All Shapes
    - Many of the shapes have a Group and this Group muts have the same ID combination as the Shape that covers it
    ie: ShapeZZ will have a GroupZZ
    Connectors
    A conector will be named according to what it connects if it is directly from ShapeA to ShapeB then the Connector is to be named ConnectorAB

    Diamonds
    These have to be named according to the Connector going To it and the Connector Leaving it
    In the case of the two Diamond shapes one comes from I and goes to K and it has the OR condition so the syntax will be applied to the Connectors and the Diamond as well
    The complete picture starting with ShapeI gpoing to ShakeK
    ShapeI - ConnectorIor - DiamondorIK - ConnectorIorK - ShapeK

    If you take this 'naming convention' into account the macro code will not require editing to make it work.

    With this in mind you create quite a big 'Flow Diagram'

    In principle, clicking on a Green Shape will return it to Dark Blue and clicking on the previous Grey Shape will hide the next step and color the Grey one DarkBlue, this part does not work entirely well but it was fun to try to think of a way to do it.

    I decided to give the file tomorrow's date and a new version number
    Attached Files Attached Files

  22. #22
    Registered User
    Join Date
    04-08-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    57

    Re: Macro that can be assigned to a shape that records selection

    Worked a bit on this tonight but didn't feel like I made enough progress to update the version number just yet... fixed your date format for you though! Lol

    I think I understand the naming convention but I'm having a bit of an issue when trying to copy a shape to create a new "shape". When I do this I update the shape name (Shape201003/Group201003 in the attached) but when I add the Shape_Name and Shape_Text to the Admin Sheet, both the source shape and the newly named shape will disappear. Not sure what I'm missing here.

    Also if I change the shape name for "ShapeD", once I update the admin sheet with the new name it works, but Shape201001 (formally ShapeA) disappears.

    Going back to the Diamond shape, I shouldn't need to use them in the working flow chart. I think how I will handle "OR" function is to have two unique shapes depending on which parent was used to arrive to it... For example, 1 tech which could be reached by either of 2 prerequisites would actually have 2 shapes... (555555a for the first rereq. and 555555b for the 2nd) Does that make sense? Thoughts on this solution?
    Attached Files Attached Files

  23. #23
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: Macro that can be assigned to a shape that records selection

    Sent you a PM
    Cheers
    Hans

  24. #24
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: Macro that can be assigned to a shape that records selection

    Corrected your file, take a look and see if it makes sense, also modified the code to include a Final shape.
    See Admin Sheet column Final Shape
    DONT group the group and the Shape it will then not work
    DONT explicitly name a shape, make it A B xxx whatever; the actual text IN the shape you place in the column next to Shape name as explained.
    Did not rename your file
    Attached Files Attached Files

  25. #25
    Registered User
    Join Date
    04-08-2014
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    57

    Re: Macro that can be assigned to a shape that records selection

    Replied to you PM

    Thanks!

  26. #26
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,906

    Re: Macro that can be assigned to a shape that records selection

    Got it
    Will take a look at it

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Name conflict error due to shape assigned with macro that needs arguments
    By siva1612 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-14-2016, 06:06 AM
  2. Excel Upgrade to 2013, Macro runs erratically with macro assigned to button (shape)
    By sspatriots in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-17-2016, 07:23 PM
  3. Shape Position Locks When Assigned a Macro
    By primed in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-31-2014, 11:27 AM
  4. Conditional formatting on shape assigned macro
    By arvindm in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-07-2013, 11:10 AM
  5. Replies: 0
    Last Post: 11-30-2012, 01:29 PM
  6. Undefined row selection macro, assigned to multiple hyperlinks
    By AJT in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-22-2012, 07:44 PM
  7. shape (with macro assigned) flashes upon click
    By grime in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-02-2006, 01:40 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1