#1   Report Post  
Junior Member
 
Posts: 10
Default images into excel

hi good day
i am trying to call images from a local drive into excel using a validation list. i have found the following procedure from Ron Coderre over at contextures.com which i am trying to adapt.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("rngDisplayName")) Is Nothing Then
      InsertPicFromFile _
         strFileLoc:=Range("rngFileLocation").Value, _
         rDestCells:=Range("rngPicDisplayCells"), _
         blnFitInDestHeight:=True, _
         strPicName:="MyDVPic"
         
End If
End Sub
the last line (strPicName:="MyDVPic") kicks out an 1004 run time error - Range of object worksheet failed.
i think it has to do with the version it was written in, (2007) and i am using 2010.
any assistance is highly appreciated
this is the code for the module:
Code:
Sub InsertPicFromFile( _
   strFileLoc As String, _
   rDestCells As Range, _
   blnFitInDestHeight As Boolean, _
   strPicName As String)

   Dim oNewPic As Shape
   Dim shtWS As Worksheet

   Set shtWS = rDestCells.Parent

   On Error Resume Next
   'Delete the named picture (if it already exists)
   shtWS.Shapes(strPicName).Delete
   
   On Error Resume Next
   With rDestCells
      'Create the new picture
      '(arbitrarily sized as a square that is
            'the height of the rDestCells)
      Set oNewPic = shtWS.Shapes.AddPicture( _
         filename:=strFileLoc, _
         LinkToFile:=msoFalse, _
         SaveWithDocument:=msoTrue, _
         Left:=.Left + 1, Top:=.Top + 1, _
         Width:=.Height - 1, Height:=.Height - 1)
      
      'Maintain original aspect ratio, set to full size
      oNewPic.LockAspectRatio = msoTrue
      oNewPic.ScaleHeight Factor:=1, _
            RelativeToOriginalSize:=msoTrue
      oNewPic.ScaleWidth Factor:=1, _
            RelativeToOriginalSize:=msoTrue
      
      If blnFitInDestHeight = True Then
         'Resize picture to fit destination cells
         oNewPic.Height = .Height - 1
      End If
      
      'Assign the desired name to the picture
      oNewPic.Name = strPicName
   End With 'rCellDest
End Sub

Last edited by Roninn75 : March 27th 12 at 12:36 PM Reason: specify which line is creating the error
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel images nook Excel Programming 0 May 7th 09 07:08 PM
Images in Excel Benji Excel Discussion (Misc queries) 1 March 12th 09 03:53 PM
Images in Excel? jbrzez Excel Discussion (Misc queries) 1 January 30th 07 07:24 PM
Images in Excel Larry E Excel Discussion (Misc queries) 2 February 21st 06 05:28 PM
Excel DDE with images Pathis Excel Discussion (Misc queries) 0 October 21st 05 04:12 PM


All times are GMT +1. The time now is 02:19 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"