Hi all,
I have a problem that is driving me crazy. I'm pretty new to VBA/Macros. I have managed to get the macro working to insert a specific jpeg image into the right cell 'W28', however I don't know how to resize the image so that it doesn't cross over the cell borders, which it currently does. The macro is linked to a command button. There will be a few buttons, each one inserting a different signature depending on the user. Once I have the first one sorted, then it will be straight forward to do the others. Here is the code I currently have;
Sub InsertPictureIG()
InsertPictureAInRange "C:\Users\Chief Engineer\Documents\Engine Room Log\Signatures\Benn Signature.jpg", _
Range("W28")
End Sub
Sub InsertPictureAInRange(PictureFileName As String, TargetCells As Range)
' inserts a picture and resizes it to fit the TargetCells range
Dim p As Object, t As Double, l As Double, w As Double, h As Double
If TypeName(ActiveSheet) <> "Worksheet" Then Exit Sub
If Dir(PictureFileName) = "" Then Exit Sub
' import picture
Set p = ActiveSheet.Pictures.Insert(PictureFileName)
' determine positions
With TargetCells
t = .Top
l = .Left
w = .Offset(0, .Columns.Count).Left - .Left
h = .Offset(.Rows.Count, 0).Top - .Top
End With
' position picture
With p
.Top = t
.Left = l
.Width = w
.Height = h
End With
Set p = Nothing
End Sub
Can someone please help me on this?
Thanks,
Benn
Bookmarks