Inserting images from local folder in spreadsheet with VBA

jmunoz

New Member
Joined
Nov 2, 2011
Messages
2
Hallo, I have been trying to create a spreadsheet where I can insert images from a local folder directly on a spreasheet. So far I have been able to work with the following code, the only issue I have is that the images are inserted in cell B4 while I need it to be inserted in H5. Does anyone know what piece of code needs to be inserted to get the job done?

Code:
Sub pic()
     
    Dim picname As String
     
     'Get picture name from cell B10 as variable 'picname'
     
    picname = Range("B10")
    
       
     'Use variable in string'
    ActiveSheet.Pictures.Insert("Z:\pictures\" & picname & ".jpg").Select
    
   
    With Selection
        .ShapeRange.LockAspectRatio = msoTrue
        .ShapeRange.Height = 200#
        .ShapeRange.Width = 200#
        .ShapeRange.Rotation = 0#
    End With
     
End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Try:
Rich (BB code):
Option Explicit
    
Sub InsertPicx()
Dim strPicName As String
    
    strPicName = Range("B10")
    
    With ActiveSheet.Pictures.Insert("Z:\pictures\" & strPicName & ".jpg")
        .Left = Range("H5").Left
        .Top = Range("H5").Top
        .ShapeRange.LockAspectRatio = msoTrue
        .ShapeRange.Height = 200
    End With
End Sub
 
Upvote 0
You are most welcome and thank you for the feedback,

Mark
 
Upvote 0

Forum statistics

Threads
1,226,498
Messages
6,191,377
Members
453,655
Latest member
lasvegasbuffet

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top