VBA - Resizing a picture in Excel

Estevam Guilherme

New Member
Joined
Jul 16, 2015
Messages
9
The code bellow paste the picture from my form into Excel. But, how can I past the pic in the activecell?
by the way, I got this code rigth here. Copy image in userform to a worksheet

VBA Code:
Private Sub UserForm_Activate()
    PicToSheet Me.Image1, ActiveSheet
End Sub

Private Sub PicToSheet(picControl, sht As Worksheet)
    Dim p As String, L As Double, T As Double, H As Double
    p = ThisWorkbook.Path & "\" & Format(Now, "yymmdd hhmmss") & "bmp"
'save temporary image to folder
    SavePicture picControl.Picture, p
'embed image in sheet
    L = sht.Cells(1, 12).Left: T = sht.Cells(1, 12).Top
    With sht.Shapes.AddPicture(Filename:=p, linktofile:=msoFalse, savewithdocument:=msoCTrue, Left:=L, Top:=T, Width:=50, Height:=50)
        .Placement = xlMove
        .OLEFormat.Object.PrintObject = msoTrue
        .OLEFormat.Object.Locked = msoTrue
    End With
'delete temporary file
    Kill p
End Sub
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

GWteB

Well-known Member
Joined
Sep 10, 2010
Messages
2,582
Office Version
  1. 2013
Platform
  1. Windows
See if this works for you ...

VBA Code:
Private Sub UserForm_Activate()

    Dim Shp As Shape
    Set Shp = PicToSheet(Me.Image1, ActiveSheet)
    Shp.Top = ActiveCell.Top
    Shp.Left = ActiveCell.Left

End Sub


Private Function PicToSheet(picControl, sht As Worksheet) As Shape
    Dim p As String, L As Double, T As Double, H As Double
    p = ThisWorkbook.Path & "\" & Format(Now, "yymmdd hhmmss") & "bmp"
'save temporary image to folder
    SavePicture picControl.Picture, p
'embed image in sheet
    Set PicToSheet = sht.Shapes.AddPicture(Filename:=p, linktofile:=msoFalse, savewithdocument:=msoCTrue, Left:=1, Top:=1, Width:=50, Height:=50)
    With PicToSheet
        .Placement = xlMove
        .OLEFormat.Object.PrintObject = msoTrue
        .OLEFormat.Object.Locked = msoTrue
    End With
'delete temporary file
    Kill p
End Function
 

GWteB

Well-known Member
Joined
Sep 10, 2010
Messages
2,582
Office Version
  1. 2013
Platform
  1. Windows
Glad it works and thank you for the feedback :)
 
Learn Excel from Bill Jelen

Understanding data is crucial, and the easiest place to start is with Microsoft Excel.

Forum statistics

Threads
1,151,492
Messages
5,764,686
Members
425,230
Latest member
DzOus

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
Top