PDA

View Full Version : Solved: Insert Image from file



wibbers2000
05-27-2009, 05:02 AM
Hi,
I have looked at the forum but cant find the answer to this. I click a command button that transfers data from 1 sheet to another. Data and columns are irrelevant.

what I would like to do is... when this data is copied over (via a command button) is that column "B" end.xlup and offset by 3 rows to insert a picture from "C:\Users\Paul\Documents\Images\mouse.png"

I have used this file type as excel 2007 will use it and keep the transparant background. However if this becomes an issue I can change
it for an alternative file type.

The picture doent change and the user should not ne prompted to find the file.

Regards
Paul

p45cal
05-27-2009, 10:57 AM
I don't have xl2007, but in xl2003 this works, and may work in xl2007:
activesheet.Pictures.Insert("C:\Users\Paul\Documents\Images\mouse.png")should do it. It places the top left of the picture on the top left of the active cell of the active sheet. Trouble is that it doesn't like placing a picture on a sheet which is not active. To get round this try:
Dim TargetCell As Range
Set ws = Sheets("Sheet3")
Set TargetCell = ws.Cells(ws.Rows.Count, 2).End(xlUp).Offset(3)
Set xxx = ws.Pictures.Insert("C:\Users\Paul\Documents\Images\mouse.png")
xxx.Top = TargetCell.Top
xxx.Left = TargetCell.Left
'xxx.Width = xxx.Width / 2
'xxx.Height = xxx.Height / 2
'xxx.ShapeRange.PictureFormat.CropRight = 40
'xxx.ShapeRange.PictureFormat.CropBottom = 121.71I've included commented out lines of a few other adjustments that can be made.

wibbers2000
05-27-2009, 11:46 AM
Thanks p45cal

worked a treat. thanks for the extra bit at the end to allow resizing.

very much appreciated