+ Reply to Thread
Results 1 to 4 of 4

Auto-Inserting Picture or Image

  1. #1
    Registered User
    Join Date
    05-11-2007
    Location
    Bangalore, India
    MS-Off Ver
    MS Office 2013
    Posts
    58

    Auto-Inserting Picture or Image

    Dear Experts,

    Need your help...

    Code in the attached sheet helps me to insert a picture from a folder based on the cell value (A1)...

    however when I change the value it is not replacing but it is inserting a new picture...

    How can I rewrite the existing picture...?
    I want to replace/delete exsiting picture and add/insert new picture when value in A1 changes...

    please help...

    Regards,
    Harish S
    Attached Files Attached Files
    Last edited by harishs; 09-05-2013 at 11:11 AM.

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Auto-Inserting Picture or Image

    Modified to delete the old picture first:
    Attached Files Attached Files
    Gary's Student

  3. #3
    Registered User
    Join Date
    05-11-2007
    Location
    Bangalore, India
    MS-Off Ver
    MS Office 2013
    Posts
    58

    Re: Auto-Inserting Picture or Image

    Thanks a lot Jakobshavn... it worked fine...

  4. #4
    Registered User
    Join Date
    09-27-2011
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    86

    Re: Auto-Inserting Picture or Image

    Hi Harish,

    You have to capture the shape name while you are updating the image, then it will work.

    Later you can hide the specified range from end user

    Use this code:

    Sub Chk_Insrt()
    Dim fso As Object, MyDir As String, Nme As String, myPic As Object
    Dim ws As Worksheet

    Set fso = CreateObject("Scripting.FileSystemObject")
    MyDir = "D:\New\" 'Change Directory
    Nme = Sheets(1).[a1] & ".jpg" 'Change Filename
    If fso.FileExists(MyDir & Nme) Then
    Application.ScreenUpdating = 0
    Set ws = Sheets(1) 'Change the target sheet

    '--- Code Update-----
    myshapename = ws.Range("k1").Value
    ws.Shapes(myshapename).Delete
    'end

    Set myPic = ws.Pictures.Insert(MyDir & Nme)



    With myPic
    .Top = ws.[d5].Top
    .Left = ws.[d5].Left
    .ShapeRange.Height = ws.[d5].RowHeight * 4.2 '4.2 rows tall
    End With

    '--- Code Update-----
    ws.Range("k1").Value = myPic.Name
    'end

    Set myPic = Nothing: Set ws = Nothing
    Application.ScreenUpdating = 1
    End If
    Set fso = Nothing
    End Sub


    Regards,
    Loki

+ 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. Image (Picture) Issue
    By David De Rainville in forum Excel General
    Replies: 0
    Last Post: 09-14-2011, 12:30 PM
  2. image & picture
    By Tom Rudski in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-07-2005, 03:35 PM
  3. Show picture with transparencies in Image
    By Jens Meier in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-08-2005, 10:05 PM
  4. Charts to Image or Picture?
    By Bill Elerding in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 05-05-2005, 08:06 AM
  5. get a picture width and height without inserting the picture
    By Dorothy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-13-2005, 02:06 AM

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