Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Insert picture based on cell value (unlimited)

I am looking to insert a picture based on a cell value. The exact application
is to insert the picture of a person based on choosing their name from a
drop-down list. Anybody have any suggestions; VBA or other? Thank you in
advance for the help.
--
djk44
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Insert picture based on cell value (unlimited)

Record a macro whilst you insert the picture manually.

Then edit/include that in the required event, probably:
Private Sub ComboBox1_Click()
End Sub
where ComboBox1.Text gives you selected text.

Depends how you are matching the selected name to the required graphic.

NickHK

"djk44" wrote in message
...
I am looking to insert a picture based on a cell value. The exact

application
is to insert the picture of a person based on choosing their name from a
drop-down list. Anybody have any suggestions; VBA or other? Thank you in
advance for the help.
--
djk44



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Insert picture based on cell value (unlimited)

Thanks for the input. I will be using a listbox control that returns a name
(using a vlookup function). When I select the name, the assigned name of the
image will flow into the worksheet. The macro can then lookup in the same
path, the exact image name and enter the image into a given cell range
location.

When I record the macro, this is the code.
ActiveSheet.Pictures.Insert( _
"C:\Documents and Settings\Dave Knight\My Documents\My
Pictures\football.jpg"). _ '"football.jpg" is the image I would like to have
chosen by the value within a cell in the worksheet (ie. soccer.jpg,
baseball.jpg, etc.)
Select
Selection.ShapeRange.ScaleWidth 0.45, msoFalse, msoScaleFromBottomRight
Selection.ShapeRange.ScaleHeight 0.45, msoFalse, msoScaleFromBottomRight
Selection.ShapeRange.IncrementLeft -59.25
Selection.ShapeRange.IncrementTop -273#
Selection.ShapeRange.ScaleWidth 0.75, msoFalse, msoScaleFromBottomRight
Selection.ShapeRange.ScaleHeight 0.75, msoFalse, msoScaleFromBottomRight

Anymore detailed help is greatly appreciated.

--
djk44


"NickHK" wrote:

Record a macro whilst you insert the picture manually.

Then edit/include that in the required event, probably:
Private Sub ComboBox1_Click()
End Sub
where ComboBox1.Text gives you selected text.

Depends how you are matching the selected name to the required graphic.

NickHK

"djk44" wrote in message
...
I am looking to insert a picture based on a cell value. The exact

application
is to insert the picture of a person based on choosing their name from a
drop-down list. Anybody have any suggestions; VBA or other? Thank you in
advance for the help.
--
djk44




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Insert picture based on cell value (unlimited)


Based on that macro code and however you are getting the file name from the
combobox selection (called the function "GetFileNameFromValue" here), you
can

Private Sub ComboBox1_Click()
Dim FileName as string
Dim Pic As Picture

FileName = GetFileNameFromValue(ComboBox1.Text)

Set Pic = ActiveSheet.Pictures.Insert(FileName)

With Pic
.Left = 10
.Top = 10
.Width = 100
.Height = 100
End With

End Sub

<Side note
Pictures and the data type Picture are not visible in VBA help or the object
browser, but clear work. From the immediate window:
?typename(ActiveSheet.Pictures.Insert(Filename)
Picture

Maybe someone more knowledgable can explain why
</Side note

An alternative, more modern way is to use the .AddPicture

Dim ss As Shape
Set ss = ActiveSheet.Shapes.AddPicture(FileName, _
msoFalse, _
msoTrue, _
10, _
10, _
100, _
100)

This creates less flicker.

NickHK

"djk44" wrote in message
...
Thanks for the input. I will be using a listbox control that returns a

name
(using a vlookup function). When I select the name, the assigned name of

the
image will flow into the worksheet. The macro can then lookup in the same
path, the exact image name and enter the image into a given cell range
location.

When I record the macro, this is the code.
ActiveSheet.Pictures.Insert( _
"C:\Documents and Settings\Dave Knight\My Documents\My
Pictures\football.jpg"). _ '"football.jpg" is the image I would like to

have
chosen by the value within a cell in the worksheet (ie. soccer.jpg,
baseball.jpg, etc.)
Select
Selection.ShapeRange.ScaleWidth 0.45, msoFalse,

msoScaleFromBottomRight
Selection.ShapeRange.ScaleHeight 0.45, msoFalse,

msoScaleFromBottomRight
Selection.ShapeRange.IncrementLeft -59.25
Selection.ShapeRange.IncrementTop -273#
Selection.ShapeRange.ScaleWidth 0.75, msoFalse,

msoScaleFromBottomRight
Selection.ShapeRange.ScaleHeight 0.75, msoFalse,

msoScaleFromBottomRight

Anymore detailed help is greatly appreciated.

--
djk44


"NickHK" wrote:

Record a macro whilst you insert the picture manually.

Then edit/include that in the required event, probably:
Private Sub ComboBox1_Click()
End Sub
where ComboBox1.Text gives you selected text.

Depends how you are matching the selected name to the required graphic.

NickHK

"djk44" wrote in message
...
I am looking to insert a picture based on a cell value. The exact

application
is to insert the picture of a person based on choosing their name from

a
drop-down list. Anybody have any suggestions; VBA or other? Thank you

in
advance for the help.
--
djk44






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Insert picture based on cell value (unlimited)

I'll try it and let you know how it goes.


--
djk44


"NickHK" wrote:


Based on that macro code and however you are getting the file name from the
combobox selection (called the function "GetFileNameFromValue" here), you
can

Private Sub ComboBox1_Click()
Dim FileName as string
Dim Pic As Picture

FileName = GetFileNameFromValue(ComboBox1.Text)

Set Pic = ActiveSheet.Pictures.Insert(FileName)

With Pic
.Left = 10
.Top = 10
.Width = 100
.Height = 100
End With

End Sub

<Side note
Pictures and the data type Picture are not visible in VBA help or the object
browser, but clear work. From the immediate window:
?typename(ActiveSheet.Pictures.Insert(Filename)
Picture

Maybe someone more knowledgable can explain why
</Side note

An alternative, more modern way is to use the .AddPicture

Dim ss As Shape
Set ss = ActiveSheet.Shapes.AddPicture(FileName, _
msoFalse, _
msoTrue, _
10, _
10, _
100, _
100)

This creates less flicker.

NickHK

"djk44" wrote in message
...
Thanks for the input. I will be using a listbox control that returns a

name
(using a vlookup function). When I select the name, the assigned name of

the
image will flow into the worksheet. The macro can then lookup in the same
path, the exact image name and enter the image into a given cell range
location.

When I record the macro, this is the code.
ActiveSheet.Pictures.Insert( _
"C:\Documents and Settings\Dave Knight\My Documents\My
Pictures\football.jpg"). _ '"football.jpg" is the image I would like to

have
chosen by the value within a cell in the worksheet (ie. soccer.jpg,
baseball.jpg, etc.)
Select
Selection.ShapeRange.ScaleWidth 0.45, msoFalse,

msoScaleFromBottomRight
Selection.ShapeRange.ScaleHeight 0.45, msoFalse,

msoScaleFromBottomRight
Selection.ShapeRange.IncrementLeft -59.25
Selection.ShapeRange.IncrementTop -273#
Selection.ShapeRange.ScaleWidth 0.75, msoFalse,

msoScaleFromBottomRight
Selection.ShapeRange.ScaleHeight 0.75, msoFalse,

msoScaleFromBottomRight

Anymore detailed help is greatly appreciated.

--
djk44


"NickHK" wrote:

Record a macro whilst you insert the picture manually.

Then edit/include that in the required event, probably:
Private Sub ComboBox1_Click()
End Sub
where ComboBox1.Text gives you selected text.

Depends how you are matching the selected name to the required graphic.

NickHK

"djk44" wrote in message
...
I am looking to insert a picture based on a cell value. The exact
application
is to insert the picture of a person based on choosing their name from

a
drop-down list. Anybody have any suggestions; VBA or other? Thank you

in
advance for the help.
--
djk44






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I insert a picture into a cell? Evan Lapka[_2_] Excel Worksheet Functions 7 June 21st 07 10:18 PM
how do I insert picture into cell so vlookup can return picture? ah Excel Worksheet Functions 1 May 1st 07 04:38 AM
insert a picture based on a formula Analyst Excel Worksheet Functions 1 July 20th 06 01:07 PM
insert picture from file based on cel value/content Jamaican Teacher Excel Worksheet Functions 1 June 8th 06 06:27 PM
how to insert picture to the cell? Johney Salem Excel Discussion (Misc queries) 2 January 23rd 06 04:58 PM


All times are GMT +1. The time now is 01:21 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"