November 8, 2019

Copy User Form Image to Worksheet Automatically

How to copy User Form image to worksheet at a specific position automatically using VBA. This can help in creating ID cards for employees, students, etc,
Watch the video below:

Here’s the complete VBA code:
Private Sub CommandButton1_Click()
Dim shapeImage As OLEObject

With Worksheets(“Sheet1″)
Set shapeImage = .OLEObjects.Add(ClassType:=”Forms.Image.1”, _
Left:=.Cells(2, “B”).Left, _
Top:=.Cells(2, “B”).Top, _
Width:=Me.Image1.Width, _
Height:=Me.Image1.Height)
End With

With shapeImage
.Object.PictureSizeMode = 3
.Object.Picture = Me.Image1.Picture
End With

End Sub

Further reading:
PictureSizeMode property

One thought on “Copy User Form Image to Worksheet Automatically

  1. This is perfect. My code creates a new worksheet for a report that is generated in VBA – I was looking for a way to add my logo to this report when a client runs the specified reports without having to send a separate file or maintain the logo on a hidden worksheet in the file. This code does exactly that without having to save a temporary image file like many of the other suggestions I have seen.

Comments are closed.