View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
keepITcool keepITcool is offline
external usenet poster
 
Posts: 2,253
Default Displaying an image without using external files


I've simulated your combobox with a validation list..
sourced by a list of filenames in ColumnD


you'll need an Embedded Image control
from the control toolbox toolbar.

Make sure it's named "Image1"
Then run ReadFileName for the setup.

Now when cell a1 is changed the picture will follow.



Public Sub ReadFileNames()
Dim sDir$, r&

Range("D:D").Clear
'msoDialogFolderPicker only exist in OFFICE 2000+
If Application.FileDialog(msoFileDialogFolderPicker). Show = False Then
Exit Sub
sDir = Dir("*.jpg")
While sDir < vbNullString
r = r + 1
Range("D" & r) = CurDir & Application.PathSeparator & sDir
sDir = Dir()
Wend
If r 0 Then
Application.EnableEvents = False
With Range("a1")
.ClearContents

.Interior.ColorIndex = 37

.Validation.Delete
.Value = "[Select your picture]"

.Validation.Add xlValidateList, Formula1:="=$D$1:$D$" & r
End With
Application.EnableEvents = True
End If

End Sub



Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count 1 Then Exit Sub
If Target.Address = "$A$1" Then
Image1.Picture = LoadPicture(Range("a1"))
End If
End Sub








--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam

d.i.barr wrote in message
:


I am sure there must be a way to solve this because I have seen

examples
close to what I want but not quite, but my attempts so far have

failed.
I would like a user form to display an image that will not be stored

on
others' computers.

Ideally I would like the image to display an embedded object but not

by
reference of object number or name because it will change regularly
depending on user clicks in a list box (user clicks on the desired
object in the list box, code searches for the entry on the spread

sheet
and displays the relevant picture which is in a column). If possible,

I
want to display it by whats in the cell.

I know it is possible to enter a formula in a picture formula box to
display what is in or "over" that cell, but there seems to be no way

to
do it for the image box in a form (although it may be something as
simple as a syntax error, I've not been coding that long).

If this isn't possible, I will settle for the syntax to refer to an
embedded image although the resulting code may get a bit spagetti, and
of course it's good practice not to hard code absolute values.

Thanks in advance,
David Barr