VBA Picture aspect ratio

bardern88

New Member
Joined
Sep 8, 2016
Messages
2
Hi, I've got a macro to work to look up pictures and pull them through, the problem is it's automatically filling the shape with the picture but I would like the original picture to remain in the same aspect and fit the shape.

I believe I need to use Lockaspectratio = true, but can't seem to get it to work anywhere.

any help greatly appreciated.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)




If Target.Address = "$B$7" Then


On Error Resume Next




        newpic = "Y:\Packing\Excel Packing Template\Pictures\" & Range("E8").Value
      
        newpic1 = "Y:\Packing\Excel Packing Template\Pictures\" & Range("E9").Value
    
        newpic2 = "Y:\Packing\Excel Packing Template\Pictures\" & Range("E7").Value
        
        Target.Comment.Shape.Fill.UserPicture newpic1
    
      
ActiveSheet.Shapes.Range(Array("PICT1")).Insert.UserPicture.newpic
On Error Resume Next
ActiveSheet.Shapes.Range(Array("Picture 1")).Fill.UserPicture.newpic1
On Error Resume Next
ActiveSheet.Shapes.Range(Array("Picture 4")).Fill.UserPicture newpic1
On Error Resume Next
ActiveSheet.Shapes.Range(Array("Rectangle 1")).Fill.UserPicture newpic




ActiveSheet.Shapes.Range(Array("Forms.Image.1")).Fill.UserPicture newpic2
ActiveSheet.EMBED("Forms.Image.1", "").Fill newpic2




End If




End Sub
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

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