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.
Bookmarks