+ Reply to Thread
Results 1 to 6 of 6

How can I use a VBA macro to replace an existing image with file with name of cell?

  1. #1
    Registered User
    Join Date
    04-09-2020
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    3

    How can I use a VBA macro to replace an existing image with file with name of cell?

    My idea is to write a macro which is assigned to a button that does the same thing as right-clicking the image and using "Change picture..." and then uses information in a cell to find the correct picture (Lastname, firstname.jpg).

    Having never worked with excel macros before, you can imagine my dilemma.

    Lets say all the pictures are stored under this file path: C:\MyLocalData\john.smith\Pictures\Portraits
    and all use this naming convention: LASTNAME, FIRSTNAME.JPG

    If someone could help me out with this issue that would be amazing! Thanks in advance.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: How can I use a VBA macro to replace an existing image with file with name of cell?

    Add an ActiveX image control to the Sheet. It's easier to control the size and position of the picture.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    04-09-2020
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    3

    Re: How can I use a VBA macro to replace an existing image with file with name of cell?

    AlphaFrog Wow! It worked!

    Thank you so much for the help. The code you provided seems to be working, however, the picture is inserted sideways (landscape rather than the desired portrait orientation) and I was wondering if I can add a black border? Any ideas?

    Thanks again! First real progress in days haha
    Last edited by henki111; 04-09-2020 at 07:46 PM.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: How can I use a VBA macro to replace an existing image with file with name of cell?

    Do you mean your picture is rotated 90 degrees? If yes, I would think you saved it that way. Edit your file and rotate it.

    Black Border...
    Activate Design Mode
    Right-click on the Image control and select Properties

  5. #5
    Registered User
    Join Date
    04-09-2020
    Location
    Canada
    MS-Off Ver
    2016
    Posts
    3

    Re: How can I use a VBA macro to replace an existing image with file with name of cell?

    Hey AlphaFrog,

    Yes, the image does insert rotated 90 degrees even if when I open the image file normally it has the correct orientation. I rotated, then un-rotated the image and saved it again in the correct orientation and then the image came in the correct way.

    I was wondering if you know a way to make a button that would rotate the image by 90 degrees per click? That way I could click that button whenever it does not insert right.

    Thanks!

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

    Re: How can I use a VBA macro to replace an existing image with file with name of cell?

    Hi henki111,

    I was wondering if you know a way to make a button that would rotate the image by 90 degrees per click?
    See the attached modified copy of your sample Workbook. Select a Picture or Shape, then Left Click the CommandButton to rotate the shape +90 degrees.
    This DOES NOT work on Active X Objects.

    Please Login or Register  to view this content.
    Lewis
    Attached Files Attached Files

+ 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. Copy a file from one folder to another and replace the existing file
    By KColgrove in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-17-2019, 08:21 PM
  2. VBA to cut image file path from word bookmark and replace with inserted image
    By JayRay1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-11-2018, 07:31 PM
  3. VBA to cut image file path from word bookmark and replace with inserted image
    By JayRay1 in forum Word Programming / VBA / Macros
    Replies: 1
    Last Post: 05-11-2018, 12:02 AM
  4. prompt to replace existing file
    By mixel in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-07-2007, 01:28 PM
  5. Replace an Existing File
    By Jim Skrydlak in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-08-2006, 04:55 PM
  6. Replace Existing File
    By Lynn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-21-2006, 06:20 PM
  7. [SOLVED] SaveAs macro: How do I specify "Replace existing file?"
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-23-2005, 10:06 PM

Tags for this Thread

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