Inserting a Picture from Folder over cell in 2007

  • Thread starter Thread starter ironhydroxide
  • Start date Start date
Maybe you are looking for this to add the picture on top of C3

Sub test()
Dim YourPic As Picture
With ActiveSheet.Range("C3")
Set YourPic = .Parent.Pictures.Insert("C:\Data\Picture1.jpg")
YourPic.Top = .Top
YourPic.Width = .Width
YourPic.Height = .Height
YourPic.Left = .Left
End With
End Sub
 
Sorry, yesterday the browser was giving me problems and i could not write an
explaination to my subject.

I have a loop that updates the Filename everytime it loops and it is
different every time. the loop gives me a public declared string of the
filename. (the populate is in a different subfunction as the loop.)

How do i take this string of the file (i know that the filename will be in
the stated folder) and use it for the Address of the picture to be populated.
I was successful once, but then I changed some other code (unrelated code)
and i couldnt get this snippet to work anymore.

Thanks
Ironhydroxide
 
Thanks I had the problem of not using "Set" Before a Dimensioned YourPic So
that is working Now


I now have the question of how to position the Picture over the cell that i
want. For the most part it is in the correct position but it waviers up and
down a bit covering important info beneath it.


Here is a Snippit of my code

With ActiveSheet.Cells(PopRow, PopCol)
Set yourPic = ActiveSheet.Pictures.Insert(Picstring)
yourPic.Top = Cells(PopRow, PopCol).Top 'Here i expect the picture
to be set alligned with the top of the cell. (apparently it isnt working
correctly or i am having a different problem)
yourPic.Width = Cells(PopRow, PopCol).Width
yourPic.Height = Cells(PopRow, PopCol).Height
yourPic.Left = Cells(PopRow, PopCol).Left 'Here i expect the
picture to be set alligned with the side of the cell. (this seems to be
working perfectly)
End With

Hopefully you can answer this question also.

Ironhydroxide
 
FOUND IT!

I swapped the yourPic.Top = Cells(PopRow, PopCol).Top from the top to the
bottom of the set of cell moving/sizing commands.

Thanks anyways
 
Back
Top