Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

picture in excel 1

Status
Not open for further replies.

willybgw

Programmer
May 30, 2003
55
US
I am trying to import a picture into an excel 2000 spreadsheet based on the value in cell A1. The folling code gives me a #VALUE! error. Cell B12 has
=MYPIC() in it. Any suggestions?



Function MYPIC() As Object

Dim myXl As Object
Dim PATH As String
Dim FILE As String

Set FILE = CELL.Range("A1").Value
PATH = "X:\PICTURES" & FILE & ".JPG"

Set myXl = GetObject(, "Excel.Application")
Set MYPIC = myXl.Sheets(1).Pictures.Insert(PATH)
MYPIC.Top = myXl.Range("B12").Top
MYPIC.Left = myXl.Range("B12").Left
MYPIC.ShapeRange.Height = myXl.Range("B12").RowHeight * 12
End Function

willybgw
 
try this

Option Explicit

Function MYPIC(source As Range) As Object


Dim PATH As String
Dim FILE As String

FILE = source.Value
PATH = "X:\PICTURES\" & FILE & ".JPG"



ActiveSheet.Shapes.AddPicture PATH, True, True, 100, 100, 70, 70

End Function

Please note the function now has the source defined in the fucntion call.
the 100,100,70,70 part of the addpicture method specifies size & postion. Use online help for a description.


Your statement
PATH = "X:\PICTURES" & FILE & ".JPG"
probably should be
PATH = "X:\PICTURES\" & FILE & ".JPG"


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top