View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
NickHK NickHK is offline
external usenet poster
 
Posts: 4,391
Default Iterative creation of Image objects?

Do you really need to use Image controls (which it sounds like in your
description) ?
If you can just put the graphics on the worksheet, here are 2 methods below.
If you need to use image controls, post back.
The first method uses the more up-to-date Shapes collection, whilst the 2nd
uses the older Pictures collection.
Both are valid. Depends what you want to do with the graphics after.

Private Sub CommandButton3_Click()
Dim PicNames As Variant
Dim WS As Worksheet
Dim Pic As Picture
Dim i As Long

'Note the MultiSelect=True
PicNames = Application.GetOpenFilename("JPG Files (*.jpg), *.jpg", , , ,
True)

If Not IsArray(PicNames) Then Exit Sub

'Set to the required destination
Set WS = Worksheets(1)

For i = LBound(PicNames) To UBound(PicNames)
WS.Shapes.AddPicture PicNames(i), msoFalse, msoTrue, 10, 10 + 10 * i,
100, 100
Next

'Or
'To reduce flicker when resizing
Application.ScreenUpdating = False
For i = LBound(PicNames) To UBound(PicNames)
Set Pic = ActiveSheet.Pictures.Insert(PicNames(i))
With Pic
.Left = 200
.Top = 10 + 10 * i
.Width = .Width / 2
.Height = .Height / 2
End With
Next
Application.ScreenUpdating = True

End Sub

NickHK

wrote in message
oups.com...
Hi all,

I am currently working on a VBA program that reads image files from a
folder (Jpegs, incidentally). I have produced a mockup that requires
Image objects to already be defined (like I newbie, I just dragged them
from the toolbox!). Is it possible to iteratively create Image objects
in a Frame? For example: I have ten pictures in one folder, therefore I
would like to create objects Image1, Image2, Image3.... etc... and make
them work as thumbnails?

Being somebody who used to write (badly!) in PHP and Java, I am still
working to understand object differences!

Regards,


Gaioshin

www.xfire.com/profile/gaioshin/