+ Reply to Thread
Results 1 to 4 of 4

Excel 2010 "vlookup pictures vba" links image instead of saving it as an image

Hybrid View

  1. #1
    Registered User
    Join Date
    11-25-2013
    Location
    lille
    MS-Off Ver
    Excel 2010
    Posts
    3

    Excel 2010 "vlookup pictures vba" links image instead of saving it as an image

    Guys the code below does exactly what I want in excel 2007 but not quiet in excel 2010. I do not know what changed but it links the picture I am looking up instead of saving it as a picture. What should I do? I searched and searched on the net but couldn't find a working solution for myself. What do you suggest to save the pictures as pictures not links to the path? I want to be able to send this excel file via e-mail to my colleagues and want them to see everything they need on the excel sheet not linked to certain folders.



    Option Explicit
    Sub InsertPictures()
        Dim strPath As String
        Dim strFile As String
        Dim objPic As Picture
        Dim LastRow As Long
        Dim i As Long
        
        LastRow = Cells(Rows.Count, "A").End(xlUp).Row
        
        If LastRow = 1 Then
            MsgBox "No data is available...", vbInformation
            Exit Sub
        End If
        
        Application.ScreenUpdating = False
        
        strPath = "C:\Users\user\Desktop\"
        
        If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
        
        For i = 2 To LastRow
            strFile = Cells(i, "A").Value & ".jpg"
            If Len(Dir(strPath & strFile, vbNormal)) > 0 Then
                 Set objPic = ActiveSheet.Pictures.Insert(strPath & strFile)
                 With Cells(i, "B")
                    objPic.ShapeRange.LockAspectRatio = msoFalse
                    objPic.Left = .Left
                    objPic.Top = .Top
                    objPic.Width = .Width
                    objPic.Height = .Height
                End With
            Else
                Cells(i, "B").Value = "N/A"
            End If
        Next i
        
        Application.ScreenUpdating = True
        
    End Sub
    Thanks in advance guys.
    Last edited by neverdom; 11-25-2013 at 09:05 AM. Reason: title change

  2. #2
    Registered User
    Join Date
    11-25-2013
    Location
    lille
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Excel 2010 "vlookup pictures vba" links image instead of saving it as an image

    I still couldn't find a working solution for this problem. What to do? Anyone?

  3. #3
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Excel 2010 "vlookup pictures vba" links image instead of saving it as an image

    You must use Shapes.AddPicture rather than Pictures.Insert:
    Sub InsertPictures()
       Dim strPath                     As String
       Dim strFile                     As String
       Dim objPic                      As Shape
       Dim LastRow                     As Long
       Dim i                           As Long
    
       LastRow = Cells(Rows.Count, "A").End(xlUp).Row
    
       If LastRow = 1 Then
          MsgBox "No data is available...", vbInformation
          Exit Sub
       End If
    
       Application.ScreenUpdating = False
    
       strPath = "C:\Users\user\Desktop\"
    
       If Right(strPath, 1) <> "\" Then strPath = strPath & "\"
    
       For i = 2 To LastRow
          strFile = Cells(i, "A").Value & ".jpg"
          If Len(Dir(strPath & strFile, vbNormal)) > 0 Then
             With Cells(i, "B")
                Set objPic = ActiveSheet.Shapes.AddPicture(Filename:=strPath & strFile, linktofile:=msoFalse, _
                                                           savewithdocument:=msoCTrue, Left:=.Left, _
                                                           Top:=.Top, Width:=.Width, Height:=.Height)
                objPic.LockAspectRatio = msoFalse
             End With
          Else
             Cells(i, "B").Value = "N/A"
          End If
       Next i
    
       Application.ScreenUpdating = True
    
    End Sub

  4. #4
    Registered User
    Join Date
    11-25-2013
    Location
    lille
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: Excel 2010 "vlookup pictures vba" links image instead of saving it as an image

    Oh thank you very much it works perfectly!

+ 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. Replies: 2
    Last Post: 07-17-2013, 12:12 PM
  2. Extract and display image URL from "Linked image cannot be displayed" pictures
    By apyken in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-12-2013, 09:52 PM
  3. Replies: 2
    Last Post: 05-12-2013, 09:51 PM
  4. excel 2010 VBA InsertPicInRange only makes shortcut to image instead of copy of image
    By ArjanSpit in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-10-2012, 02:57 PM
  5. [SOLVED] Automatically adding image extension ".jpg" to end of image name
    By Alain in forum Excel General
    Replies: 1
    Last Post: 08-03-2006, 08:00 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