+ Reply to Thread
Results 1 to 3 of 3

Applying named image in a document to a shape

  1. #1
    Registered User
    Join Date
    07-21-2012
    Location
    UK
    MS-Off Ver
    Excel 365 for Enterprise - Windows PC
    Posts
    12

    Applying named image in a document to a shape

    Hi All

    I've been trying to see if this could be done or not.

    I've been working with a worksheet where I have set up a set of shapes to act as buttons. I have a small piece of code which will reposition these back to their default positions and reset their colours to the ones I have chosen. (Some of the users of this sheet constantly move things around accidently and can't get them back....)

    What I want to do it to add images to these shapes/buttons so that when a user clicks on them they change image to show that they were selected.

    I can add images to my document fine, name them etc, but when applying a picture to a shape it will only add a link to the image file. I've added images to my sheet with "Save with document" set, but still i can only link to the file and not the image which is inserted into my sheet.

    What I want to do is something like this:

    add an image to my sheet and name it ButtonImage1. (I can do this)
    Select button1
    addpicture "buttonImage1" to button1 (not to add the link to the file, but add the named image stored within the document)

    I can then add a loop to apply this named image to each button shape in my document.
    This way the image will not be linked to a file on the drive, but to the named image I created earlier.

    is this possible?

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Applying named image in a document to a shape

    Hi RobRobby,

    Very interesting question. See the attached file which uses the 'Group' attribute and appropriate naming of shapes to toggle the visibility of images on a Shape. Grouping is not absolutely necessary, but it seemed like 'herding cats' when the shapes were not grouped.

    The file is adapted from an old application. The items of interest to you are located on the bottom part of 'Sheet1'.

    I created a Group consisting of a Shape and two images. I created the group as follows:
    a. Created Cyan Shape. Renamed Shape to Shape01 (Renaming Macro is included).
    b. Imported .jpg Red Image. Renamed Image to Image01A.
    c. Imported .jpg Green Image. Renamed Image to Image01B.
    d. Held down 'Ctrl' Key. Selected (Left Clicked) all 3 items. 'Right Clicked' > Grouping > Group
    e, Renamed the Group to 'Group01'.
    NOTE:
    1. You probably want to have all the images on top of each other.
    2. Instead of using the Visible attribute, the ZOrder attribute can be used to put a SPECIFIC IMAGE on top.

    Applicable code in Ordinary Code module ModGroup:
    Please Login or Register  to view this content.
    Rename Shape Code in Ordinary Code Module ModNextButton:
    Please Login or Register  to view this content.
    It is a best practice to declare all variables. If you misspell a variable in your code, VBA will silently assume it is a Variant variable and go on executing with no clue to you that you have a bug. Go to the VBA development window, click Tools, Options, and check "Require Variable Declaration." This will insert the following line at the top of all new modules:
    Please Login or Register  to view this content.
    This option requires all variables to be declared and will give a compiler error for undeclared variables.

    If you need additional help, you will probably have to upload a sample workbook.

    Lewis

  3. #3
    Registered User
    Join Date
    07-21-2012
    Location
    UK
    MS-Off Ver
    Excel 365 for Enterprise - Windows PC
    Posts
    12

    Re: Applying named image in a document to a shape

    Many thanks Lewes.

    That is exactly what I need but in a far more efficient way.
    Excellent idea of grouping objects like that.

    Thanks again. I'll definetly be modifying my code to use those ideas.

    Regards

    Rob

+ 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. Shape buttons - Switch background image of shape on click and exit - referenced jpg
    By ApatheticAndrew in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-14-2015, 08:06 AM
  2. [SOLVED] Image Embed into a Shape from a URL?
    By bmasella in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 07-28-2014, 03:18 PM
  3. Applying If statement to Image's?
    By sur4j in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-09-2014, 05:20 PM
  4. [SOLVED] Use a button to control a macro that inserts an image into a shape or resets the shape
    By nwb in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-13-2013, 04:41 PM
  5. Applying Copied Image to All Worksheets in Workbook.
    By Berdman in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-24-2012, 09:41 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