for i...next i over images in a sheet

F

furbiuzzu

i've 2 little problems i'm not able to solve.

i've to associate a specific picture to each images in my active sheet.
(the number of images may be variable depending on the number of
connected data).
let's say i want to associate a different picture to each of my images.

so i've created a list like that:

cell1 >> image1 ->> image1.picture= loadpicture (file1.gif)
cell2 >> image2 ->> image2.picture= loadpicture (file2.gif)
.......
.......
cell10 >> image10 ->> image10.picture= loadpicture (file10.gif)
.......
.......
cell100 >> image100 ->> image100.picture= loadpicture (file100.gif)

Question 1

i would like to write a routine with a for i... next command able to
associate the right file to each of my images...

the problem is that a routine like the following doesn't work:

Sub associate_immages()

Dim path As String
Dim i As Integer

Sheets("team").Select
For i = 1 To 20
path = Worksheets("team").Range("GW" & i + 1).Value
Activesheet."image" & i.picture = LoadPicture(path)
Next i
End Sub

i've tried also with

'Sheets("team").form("image" & i).picture = LoadPicture(path)

and

'Sheets("team").shapes("image" & i).picture = LoadPicture(path)

but again i've an error message.

how can i solve this problem??


Question 2

some of the images should not be associated with any picture leaving
the backstyle completely transparent....

how can i delete the previous picture (using the same routine as
before) leaving the image "empty" ??


thanks in advance for your help.
 
T

Tom Ogilvy

Dim path As String
Dim i As Integer

Sheets("team").Select
For i = 1 To 20
path = Worksheets("team").Range("GW" & i + 1).Value
Activesheet.OleObjects("image" & i).Object.picture = LoadPicture(path)
Next i
End Sub


#2
Activesheet.OleObjects("image" & i).Object.picture = loadpicture("")
 
F

furbiuzzu

Tom Ogilvy ha scritto:
Dim path As String
Dim i As Integer

Sheets("team").Select
For i = 1 To 20
path = Worksheets("team").Range("GW" & i + 1).Value
Activesheet.OleObjects("image" & i).Object.picture = LoadPicture(path)
Next i
End Sub


#2
Activesheet.OleObjects("image" & i).Object.picture = loadpicture("")

thanks a lot !!!

i'll try it as soon as possible, now i'm not at home.

but i've encountered another problem in the command

Loadpicture(path)

the variable path as you can see is related with a cell where i merge
the "s before and after the "real" path.... do you think i'll encounter
the same problem with your code lines?
 
T

Tom Ogilvy

My code didn't alter any other part of what you posted, so it should behave
no differently.

You shouldn't be adding double quotes around the path string.

spath = Activecell.Value

not
spath = """" & ActiveCell.Value & """"
 
F

furbiuzzu

Tom Ogilvy ha scritto:
My code didn't alter any other part of what you posted, so it should behave
no differently.

You shouldn't be adding double quotes around the path string.

spath = Activecell.Value

not
spath = """" & ActiveCell.Value & """"

problem solved!
thanks again!

regards,
Fulvio Salvo
 

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

Top