Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Iterative creation of Image objects?

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/

  #2   Report Post  
Posted to microsoft.public.excel.programming
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/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Iterative creation of Image objects?


Hi Nick,

Thanks for your reply and code. Basically, I have a pool of images and
I want to be able to tag them, thereby toggling a flag alongside the
appropriate filename stored in a worksheet - for example, for three
items of dog.jpg, cat.jpg and chinchilla.jpg, there would be a column
with their names in plus the adjacent column. A form would then load
the thumbnails into a frame, and then the user upon clicking on the
thumbnail of the dog, will be able to see a "CLICKED" in the cell in
the column adjacent to the cell containing dog.jpg.

I'll give the code a try in a moment and see where I fall over next!

Regards,


Gaioshin


On Jan 23, 3:38 am, "NickHK" wrote:
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 ooglegroups.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/- Hide quoted text -- Show quoted text -


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
printobject for image objects [email protected] Excel Worksheet Functions 2 March 1st 05 08:33 PM
Bitmap data of Image controls & Picture objects... MDB[_2_] Excel Programming 0 November 5th 04 08:30 PM
Bitmap data of Image controls & Picture objects... MDB Excel Programming 1 November 4th 04 06:35 AM
moving excel objects pasted as an image in Powerpoint Iker Excel Programming 1 September 24th 04 04:39 AM
Naming objects on creation Andy Excel Programming 3 November 25th 03 12:40 AM


All times are GMT +1. The time now is 09:18 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"