multiple dynamic picture on excel

sergenelles

New Member
Joined
Sep 17, 2011
Messages
9
I want to create a flexible report that I can print out and give my customer.
I make a list of product we sell, and I like to have the picture of the selected product on the left.

I have the VBA that can make change the picture, but i can make it work for only 1 picture has the "worksheet change" vba can only be used for 1 time

I don't know how to make it repeat for all the needed cells.

such system is so good for all people who need many pictures to be updated.

thank you

serge
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
I would have thought the Worksheet_Change event would run each time the worksheet changes. Can you explain a bit more the steps you want to happen and then maybe I can help with a solution.
 
Upvote 0
Hello,

Yes you are right, every time there is a change, it changes the indicated cell.
But we can indicate only 1 target, but I have so many cells that I need to change.


here is the code for VBA
--------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Range)
InsertPicFromFile _
strFileLoc:=Range("fileroot").Value, _
rDestCells:=Range("picok"), _
blnFitInDestHeight:=True, _
strPicName:="picselect"
End Sub


Sub InsertPicFromFile( _
strFileLoc As String, _
rDestCells As Range, _
blnFitInDestHeight As Boolean, _
strPicName As String)

Dim oNewPic As Shape
Dim shtWS As Worksheet

Set shtWS = rDestCells.Parent

On Error Resume Next
'Delete the named picture (if it already exists)
shtWS.Shapes(strPicName).Delete

On Error Resume Next
With rDestCells
'Create the new picture
'(arbitrarily sized as a square that is the height of the rDestCells)
Set oNewPic = shtWS.Shapes.AddPicture( _
Filename:=strFileLoc, _
LinkToFile:=msoFalse, _
SaveWithDocument:=msoTrue, _
Left:=.Left + 1, Top:=.Top + 1, Width:=.Height - 1, Height:=.Height - 1)

'Maintain original aspect ratio and set to full size
oNewPic.LockAspectRatio = msoTrue
oNewPic.ScaleHeight Factor:=1, RelativeToOriginalSize:=msoTrue


------------------------------------

as you can see the destination cell is at only 1 place, can not be at different cells in the same time.

thank you

serge
 
Upvote 0
sorry, i forgot to say that I use excel 2003.

also it must have a way to indicate the target string for each pictures.

thank you

serge
 
Upvote 0
The Range object that gets passed in contains all of the cells that changed. So what you need to do is loop through each range in the Range object and then call the sub InsertPicFromFile. So your Worksheet_Change sub would look something like, if not exactly like,...

Private Sub Worksheet_Change(ByVal Target As Range)
Dim changedRange as Range
for each changedRange in Target
InsertPicFromFile _
strFileLoc:=Range("fileroot").Value, _
rDestCells:=Range(changedRange.Address), _
blnFitInDestHeight:=True, _
strPicName:="picselect"
next
End Sub
 
Last edited:
Upvote 0
I tried, it doesn't work

there is yellow hi-light for these words

InsertPicFromFile _
strFileLoc:=Range("fileroot").Value, _
rDestCells:=Range("picok"), _
blnFitInDestHeight:=True, _
strPicName:="picselect"
End Sub
 
Upvote 0
I have first a message miss match,
but now i changed the things a bit,
and i have a picture to appear where is the active cell,

if i move the mouse, change the item reference,
the picture disappears, and appear in the new active cell.

if i move the mouse but don't try to change any reference number,
the picture stays at the first cell

also the picture in not changing of "picture". it stays at the same picture,
just move of place

I also wonder what made the computer select this picture and not another

funny,..

thank you to try,..

serge
 
Upvote 0
Thank you John,
I have excel 2003, so i suppose it is a bit different.
this way, you need to make a copy of all your picture and make your excel file really heavy.
I wanted to find a VBA that takes the picture from another file.
Thank you for the suggestion
serge
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,297
Members
452,903
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top