(Solved) – Save image in excel using VBA

(solved)-–-save-image-in-excel-using-vba

I have a situation at work where people have to manually introduce pictures in a certain page of excel and resize it also manually. As a complete very beginner I’ve managed to find some VBA code to help introduce the picture by clicking a button and inserting it in a certain range of cells. The problem that I have is that I cannot figure out (after searching many posts) how to correctly introduce the function to save the image without making a link to it so others can see the report without getting an error that the picture doesn’t exist.

Can you kindly help me and complete where the function should be introduced?

Private Sub CommandButton3_Click()
Dim strFileName As String
Dim objPic As Picture
Dim rngDest As Range
strFileName = Application.GetOpenFilename( _
    FileFilter:="Images (*.jpg;*.gif;*.png),*.jpg;*.gif;*.png", _
    Title:="Please select an image...")
If strFileName = "False" Then Exit Sub
Set rngDest = Me.Range("B24:C26")
Set objPic = Me.Pictures.Insert(strFileName)
With objPic
    .ShapeRange.LockAspectRatio = msoFalse
    .Left = rngDest.Left
    .Top = rngDest.Top
    .Width = rngDest.Width
    .Height = rngDest.Height
End With
End Sub

Thanks in advance!

Leave a Reply

Your email address will not be published. Required fields are marked *