Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
printobject for image objects | Excel Worksheet Functions | |||
Bitmap data of Image controls & Picture objects... | Excel Programming | |||
Bitmap data of Image controls & Picture objects... | Excel Programming | |||
moving excel objects pasted as an image in Powerpoint | Excel Programming | |||
Naming objects on creation | Excel Programming |