VBA Code to resize photo

Malcolm torishi

Board Regular
Joined
Apr 26, 2013
Messages
219
Hi
is there a code that will resize a photo saved in a fold on my desktop so I can automatically drop it in to a cell that’s already sized say 50 x 50
thank you
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
How about this with the cell that you want the picture in, selected. Please change the path in red to match your source desktop folder picture path.

Code:
Sub InsSizePic()


    With ActiveSheet.Pictures.Insert([COLOR=#ff0000]"C:\Users\UserName\Pictures\2017-06\IMG_0516.JPG"[/COLOR])
        .ShapeRange.Height = 72
        .ShapeRange.Width = 72
    End With
    
End Sub
 
Upvote 0
Or
(Select the Cell where it needs to be pasted into first)

Code:
Sub Insert_And_Size_Picture()
Dim a As String
a = CreateObject("wscript.shell").specialfolders("Desktop") & "\" & "Picture_Folder"    '<---- Change "Picture_Folder" to actual folder name
    With ActiveSheet.Pictures.Insert(a & "\" & "My_Car.JPG")    '<---- Change picture Name and extension as required
        With .ShapeRange
            .LockAspectRatio = msoFalse
            .Left = ActiveCell.Left
            .Top = ActiveCell.Top
            .Height = ActiveCell.Height
            .Width = ActiveCell.Width
        End With
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,885
Messages
6,175,182
Members
452,615
Latest member
bogeys2birdies

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