Displaying an image without using external files

  • Thread starter Thread starter d.i.barr
  • Start date Start date
D

d.i.barr

I am sure there must be a way to solve this because I have seen example
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 o
others' computers.

Ideally I would like the image to display an embedded object but not b
reference of object number or name because it will change regularl
depending on user clicks in a list box (user clicks on the desire
object in the list box, code searches for the entry on the spread shee
and displays the relevant picture which is in a column). If possible,
want to display it by whats in the cell.

I know it is possible to enter a formula in a picture formula box t
display what is in or "over" that cell, but there seems to be no way t
do it for the image box in a form (although it may be something a
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 a
embedded image although the resulting code may get a bit spagetti, an
of course it's good practice not to hard code absolute values.

Thanks in advance,
David Bar
 
hi,

I understand you like to show some of catalog display.

You can have many forms. You can call one form at a time.

Regards
S.Sures
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top