+ Reply to Thread
Results 1 to 9 of 9

Macro for creating image border upon being clicked?

  1. #1
    Registered User
    Join Date
    12-18-2008
    Location
    White Rock
    Posts
    76

    Macro for creating image border upon being clicked?

    Hello,

    I have an existing spreadsheet with macros assigned to a bunch of plain, unformatted shapes that move data around in the spreadsheets when they are clicked.

    I now need (hopefully) to find a way so that when the shape is clicked, not only does it retain its current functionality, but it adds a thick visible colored border to it's self based on the fill color of a specific cell.

    For example...
    If i had a red square, and blue square, and a orange square side by side, clicking on the red square would change things so the red square now has a 5 pixel lime green border around it because cell C3 is lime green. If I then clicked the orange square, the red square would loose its border, and the orange square would now have a 5 pixel sky blue border around it because cell D3 is sky blue.

    Any help is greatly appreciated.
    (Telling me it can't be done works too)


    -Aaron

  2. #2
    Registered User
    Join Date
    09-02-2009
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: Macro for creating image border upon being clicked?

    hi aaron

    the following will toggle the line visibility for the shape named "Oval 1" on sheet1

    Please Login or Register  to view this content.
    (To find/set shape names, highlight them and look in the name box to the left of the formula bar)

    You can set colours based on cell colours by using
    Please Login or Register  to view this content.
    or

    Please Login or Register  to view this content.
    the latter will pick the scheme colour closest matching the rgb value specified.

    hopefully you can take it from there

  3. #3
    Registered User
    Join Date
    12-18-2008
    Location
    White Rock
    Posts
    76

    Re: Macro for creating image border upon being clicked?

    Thank you a lot blackworx,

    Now when I click a shape, it gets the appropriate outline.
    Though the outline doesn't end until I click the object a second time.
    And I can't figure out how to have the outline on the first object disapear once the second object is clicked.

    Any insight is appreciated,

    Thanks =]


    -Aaron

  4. #4
    Registered User
    Join Date
    09-02-2009
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: Macro for creating image border upon being clicked?

    Hi cheshire, you're welcome. It's easiest to explain by example - see attachment
    Attached Files Attached Files
    Last edited by blackworx; 09-03-2009 at 06:18 AM. Reason: Update attachment

  5. #5
    Registered User
    Join Date
    12-18-2008
    Location
    White Rock
    Posts
    76

    Re: Macro for creating image border upon being clicked?

    Blackworx you're amazing!

    That's absolutely perfect!

    I dont know if I'm doing something wrong / if my computer is just weird, but when I use that code, the shape is only ever given a black outline.

    I'm glad I started writing this post, in doing so my brain solved the issue.

    The 'if' statement in 'dolines' where you assigned the .forecolor. s,
    (I presume) because you were enabling the line to visible after the fact, the line was only appearing as the default black.

    So I removed the 'use' if statement, moved the ".line.visible" to the first position within the 'With' statement, and replaced "doLines shpCurrent:=Sheet1.Shapes("useG3")" with "doLines shpCurrent:=ActiveSheet.Shapes(Application.Caller)".

    Works wonderfully and I never have to re-create the macro while using multiple items.

    Thank you so much ^_^


    -Aaron
    Last edited by Cheshire; 09-04-2009 at 01:09 PM.

  6. #6
    Registered User
    Join Date
    12-18-2008
    Location
    White Rock
    Posts
    76

    Re: Macro for creating image border upon being clicked?

    A follow up question,

    the line:
    .Line.ForeColor.SchemeColor = .Parent.Range(Mid(.Name, 4)).Interior.ColorIndex + 7

    instead of pointing to a cell based on the shape's name, i need it to point to a cell on a seperate sheet. I dont quite know how to go about that. =/

    I tried the following and it doesn't seem to work?
    .Line.ForeColor.SchemeColor = .Parent.Range(Sheets(1).Cells(107, 3)).Interior.ColorIndex + 7

  7. #7
    Registered User
    Join Date
    09-02-2009
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: Macro for creating image border upon being clicked?

    Hi Aaron,

    The ".Parent" part of the original code tells Excel to look at whatever sheet the shape belongs to, so what you want is to replace that with a reference to the required sheet.

    So, instead of:
    Please Login or Register  to view this content.
    we want something like:
    Please Login or Register  to view this content.
    (This assumes that all the cells you want to refer to are contained on the same sheet.)

  8. #8
    Registered User
    Join Date
    12-18-2008
    Location
    White Rock
    Posts
    76

    Re: Macro for creating image border upon being clicked?

    Sounds good,

    Unfortunately I am looking up data across three+ seperate sheets for the colour data. Currently using a custom function which is a variant of vlookup that scans all sheets instead of just one sheet for most of my search requirements.

    To be clear, in your function ' Range(Mid(.Name, 4)) ' is just referring to the naming convention you used on your shapes to include the cell range to which they refer? Asking to ensure that I could replace it with something like ' Range("c4") ', or more likely something like ' Range(initializedVariable) '.

  9. #9
    Registered User
    Join Date
    09-02-2009
    Location
    Edinburgh, Scotland
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: Macro for creating image border upon being clicked?

    Hi Aaron, that's right. In my example, you could pass the required range like so:

    Please Login or Register  to view this content.
    The call would look like:
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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