Insert Picture In Cell

Macgyver

New Member
Joined
Jul 14, 2004
Messages
40
Hi. I'm trying to figure out a way to paste a piture above an active cell. I need the picture to be left justified (align left). I've come across the following code and have modified it slightly to suit my needs, however it pastes the picture above the center of the active cell. Thanks in advance.


<code>
Sub InsertTickmark()
InsertPicture "C:\Pfx Engagement\WM\Tickmark\Agrees to.bmp", _
ActiveCell, True, True
End Sub

Sub InsertPicture(PictureFileName As String, TargetCell As Range, _
CenterH As Boolean, CenterV As Boolean)
' inserts a picture at the top left position of TargetCell
' the picture can be centered horizontally and/or vertically
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 TargetCell
t = .Top
l = .Left
If CenterH Then
w = .Offset(0, 1).Left - .Left
l = l + w / 2 - p.Width / 2
If l < 1 Then l = 1
End If
If CenterV Then
h = .Offset(1, 0).Top - .Top
t = t + h / 2 - p.Height / 2
If t < 1 Then t = 1
End If
End With
' position picture
With p
.Top = t
.Left = l

End With
Set p = Nothing
End Sub

</code>
 

BrianB

Well-known Member
Joined
Feb 17, 2003
Messages
8,127
You are more likely to get replies if you format your code correctly so it is easy to read on screen.

picture above an active cell.
Make the picture .Top = cell .Top minus picture .Height

I need the picture to be left justified (align left).
Make the picture .Left = to the cell .Left.
 

Forum statistics

Threads
1,082,575
Messages
5,366,415
Members
400,888
Latest member
Cdim7

Some videos you may like

This Week's Hot Topics

Top