Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Loop through image controls on worksheet

I'm attempting to set the picture property of several image controls on a
single worksheet (not on a user form). For example, three image controls
(named Image1, Image2, and Image3) on Sheet 1:

Sheet1.Image1.Picture = LoadPicture("C:\Pic1.jpg")
Sheet1.Image2.Picture = LoadPicture("C:\Pic2.jpg")
Sheet1.Image3.Picture = LoadPicture("C:\Pic3.jpg")

Can anyone suggest a way to set the picture property for each image by
looping rather than repeating the loadpicture for each image as above?
Thanks in advance.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Loop through image controls on worksheet



method 1
for i = 1 to 3
set pict = LoadPicture("C:\pic" & i & ".jpg")

next i


method 2

folder = "c:\"
PictName = array(Pic1.jpg,Pic2.jpg,Pic3.jpg)
for each picture in PictName
set pict = LoadPicture(Folder & picture)
next picture


You can set the picture properties using pict.left = .5 or any equivalent
property.
"Paul Mathews" wrote:

I'm attempting to set the picture property of several image controls on a
single worksheet (not on a user form). For example, three image controls
(named Image1, Image2, and Image3) on Sheet 1:

Sheet1.Image1.Picture = LoadPicture("C:\Pic1.jpg")
Sheet1.Image2.Picture = LoadPicture("C:\Pic2.jpg")
Sheet1.Image3.Picture = LoadPicture("C:\Pic3.jpg")

Can anyone suggest a way to set the picture property for each image by
looping rather than repeating the loadpicture for each image as above?
Thanks in advance.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Loop through image controls on worksheet

Joel, thanks for the speedy reply. I'm not following how the code loads each
of the three image controls with its own jpg image. That is, how do I
declare your variable, "pict" so that it is an object that refers to the
Image1 control when i=1, Image2 when i=2, and Image3 when i=3? Thanks again,
much appreciated.

"Joel" wrote:



method 1
for i = 1 to 3
set pict = LoadPicture("C:\pic" & i & ".jpg")

next i


method 2

folder = "c:\"
PictName = array(Pic1.jpg,Pic2.jpg,Pic3.jpg)
for each picture in PictName
set pict = LoadPicture(Folder & picture)
next picture


You can set the picture properties using pict.left = .5 or any equivalent
property.
"Paul Mathews" wrote:

I'm attempting to set the picture property of several image controls on a
single worksheet (not on a user form). For example, three image controls
(named Image1, Image2, and Image3) on Sheet 1:

Sheet1.Image1.Picture = LoadPicture("C:\Pic1.jpg")
Sheet1.Image2.Picture = LoadPicture("C:\Pic2.jpg")
Sheet1.Image3.Picture = LoadPicture("C:\Pic3.jpg")

Can anyone suggest a way to set the picture property for each image by
looping rather than repeating the loadpicture for each image as above?
Thanks in advance.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Loop through image controls on worksheet

You can declare Pict as object.

I was expecting you to add all your code inside the loop

for i = 1 to 3
set pict = LoadPicture("C:\pic" & i & ".jpg")
pict.left = 50
pict.top = 100
next i


Pict in my examples would refere only to the latest pict loaded. Each time
a new pict is loaded it would erase the old information.


If you need to refence each of the pictures yo ucan do something like this
pict1 = LoadPicture("C:\Pic1.jpg")
pict2 = LoadPicture("C:\Pic2.jpg")
Pict3 = LoadPicture("C:\Pic3.jpg")

You can create an arrry of pictures

Dim pict(3)
pict(1) = LoadPicture("C:\Pic1.jpg")
pict(2) = LoadPicture("C:\Pic2.jpg")
Pict(3) = LoadPicture("C:\Pic3.jpg")

The loop for this would be this
for i = 1 to 3
pict(i) = LoadPicture("C:\Pic" & i & ".jpg")
next i

If you uknow the names of the pictures yo ucan od this

set pict = shapes("Pic1.jpg")



"Paul Mathews" wrote:

Joel, thanks for the speedy reply. I'm not following how the code loads each
of the three image controls with its own jpg image. That is, how do I
declare your variable, "pict" so that it is an object that refers to the
Image1 control when i=1, Image2 when i=2, and Image3 when i=3? Thanks again,
much appreciated.

"Joel" wrote:



method 1
for i = 1 to 3
set pict = LoadPicture("C:\pic" & i & ".jpg")

next i


method 2

folder = "c:\"
PictName = array(Pic1.jpg,Pic2.jpg,Pic3.jpg)
for each picture in PictName
set pict = LoadPicture(Folder & picture)
next picture


You can set the picture properties using pict.left = .5 or any equivalent
property.
"Paul Mathews" wrote:

I'm attempting to set the picture property of several image controls on a
single worksheet (not on a user form). For example, three image controls
(named Image1, Image2, and Image3) on Sheet 1:

Sheet1.Image1.Picture = LoadPicture("C:\Pic1.jpg")
Sheet1.Image2.Picture = LoadPicture("C:\Pic2.jpg")
Sheet1.Image3.Picture = LoadPicture("C:\Pic3.jpg")

Can anyone suggest a way to set the picture property for each image by
looping rather than repeating the loadpicture for each image as above?
Thanks in advance.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Loop through image controls on worksheet

Option Explicit
Sub testme()
Dim iCtr As Long
For iCtr = 1 To 3
Sheet1.OLEObjects("Image" & iCtr).Object.Picture _
= LoadPicture("c:\pict" & iCtr & ".jpg")
Next iCtr
End Sub

Paul Mathews wrote:

I'm attempting to set the picture property of several image controls on a
single worksheet (not on a user form). For example, three image controls
(named Image1, Image2, and Image3) on Sheet 1:

Sheet1.Image1.Picture = LoadPicture("C:\Pic1.jpg")
Sheet1.Image2.Picture = LoadPicture("C:\Pic2.jpg")
Sheet1.Image3.Picture = LoadPicture("C:\Pic3.jpg")

Can anyone suggest a way to set the picture property for each image by
looping rather than repeating the loadpicture for each image as above?
Thanks in advance.


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Loop through image controls on worksheet

Dave, Joel, thank you both very much. Dave, the code you provided is
precisely what I was looking for (I couldn't quite figure out how to use the
OLEObjects method so that I could specify a string name for each image
control and you nailed it with your solution). I appreciate the time you
took to provide this solution to me and the rest of the Excel community.

Paul Mathews

"Dave Peterson" wrote:

Option Explicit
Sub testme()
Dim iCtr As Long
For iCtr = 1 To 3
Sheet1.OLEObjects("Image" & iCtr).Object.Picture _
= LoadPicture("c:\pict" & iCtr & ".jpg")
Next iCtr
End Sub

Paul Mathews wrote:

I'm attempting to set the picture property of several image controls on a
single worksheet (not on a user form). For example, three image controls
(named Image1, Image2, and Image3) on Sheet 1:

Sheet1.Image1.Picture = LoadPicture("C:\Pic1.jpg")
Sheet1.Image2.Picture = LoadPicture("C:\Pic2.jpg")
Sheet1.Image3.Picture = LoadPicture("C:\Pic3.jpg")

Can anyone suggest a way to set the picture property for each image by
looping rather than repeating the loadpicture for each image as above?
Thanks in advance.


--

Dave Peterson

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Loop through image controls on worksheet

I don't normally put image controls on worksheets. I just plop the pictures
where I want them.

Is there a reason you don't use the plain old pictures?

Just curious.

Paul Mathews wrote:

Dave, Joel, thank you both very much. Dave, the code you provided is
precisely what I was looking for (I couldn't quite figure out how to use the
OLEObjects method so that I could specify a string name for each image
control and you nailed it with your solution). I appreciate the time you
took to provide this solution to me and the rest of the Excel community.

Paul Mathews

"Dave Peterson" wrote:

Option Explicit
Sub testme()
Dim iCtr As Long
For iCtr = 1 To 3
Sheet1.OLEObjects("Image" & iCtr).Object.Picture _
= LoadPicture("c:\pict" & iCtr & ".jpg")
Next iCtr
End Sub

Paul Mathews wrote:

I'm attempting to set the picture property of several image controls on a
single worksheet (not on a user form). For example, three image controls
(named Image1, Image2, and Image3) on Sheet 1:

Sheet1.Image1.Picture = LoadPicture("C:\Pic1.jpg")
Sheet1.Image2.Picture = LoadPicture("C:\Pic2.jpg")
Sheet1.Image3.Picture = LoadPicture("C:\Pic3.jpg")

Can anyone suggest a way to set the picture property for each image by
looping rather than repeating the loadpicture for each image as above?
Thanks in advance.


--

Dave Peterson


--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 84
Default Loop through image controls on worksheet

Hi Dave, yes you're right, this is a pretty darned strange thing to do.
Let's call it an experiment at this point. I guess it's best described as
something of an Excel photo viewer (i.e., click a forward or back button and
see pictures change on a worksheet as well as text; the text and picture file
names are sourced from a data table in another worksheet). I may well end up
doing the standard insertion of pictures from files into the worksheet but I
was curious about this approach (image controls do have the nice feature of
providing automatic sizing of a loaded picture using the PictureSizeMode
property). Thanks again for indulging me.

"Dave Peterson" wrote:

I don't normally put image controls on worksheets. I just plop the pictures
where I want them.

Is there a reason you don't use the plain old pictures?

Just curious.

Paul Mathews wrote:

Dave, Joel, thank you both very much. Dave, the code you provided is
precisely what I was looking for (I couldn't quite figure out how to use the
OLEObjects method so that I could specify a string name for each image
control and you nailed it with your solution). I appreciate the time you
took to provide this solution to me and the rest of the Excel community.

Paul Mathews

"Dave Peterson" wrote:

Option Explicit
Sub testme()
Dim iCtr As Long
For iCtr = 1 To 3
Sheet1.OLEObjects("Image" & iCtr).Object.Picture _
= LoadPicture("c:\pict" & iCtr & ".jpg")
Next iCtr
End Sub

Paul Mathews wrote:

I'm attempting to set the picture property of several image controls on a
single worksheet (not on a user form). For example, three image controls
(named Image1, Image2, and Image3) on Sheet 1:

Sheet1.Image1.Picture = LoadPicture("C:\Pic1.jpg")
Sheet1.Image2.Picture = LoadPicture("C:\Pic2.jpg")
Sheet1.Image3.Picture = LoadPicture("C:\Pic3.jpg")

Can anyone suggest a way to set the picture property for each image by
looping rather than repeating the loadpicture for each image as above?
Thanks in advance.

--

Dave Peterson


--

Dave Peterson

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Loop through image controls on worksheet

Ah. That seems like a reasonable thing to try.

If you're working with pictures, you may want to use http://www.irfanview.com.
It's a nice picture viewer with lots of features. You can make a pdf file of
thumbnail sized pictures.

And http://picasa.google.com may be of use if you want a free basic photo
editor/organizer.

Paul Mathews wrote:

Hi Dave, yes you're right, this is a pretty darned strange thing to do.
Let's call it an experiment at this point. I guess it's best described as
something of an Excel photo viewer (i.e., click a forward or back button and
see pictures change on a worksheet as well as text; the text and picture file
names are sourced from a data table in another worksheet). I may well end up
doing the standard insertion of pictures from files into the worksheet but I
was curious about this approach (image controls do have the nice feature of
providing automatic sizing of a loaded picture using the PictureSizeMode
property). Thanks again for indulging me.

"Dave Peterson" wrote:

I don't normally put image controls on worksheets. I just plop the pictures
where I want them.

Is there a reason you don't use the plain old pictures?

Just curious.

Paul Mathews wrote:

Dave, Joel, thank you both very much. Dave, the code you provided is
precisely what I was looking for (I couldn't quite figure out how to use the
OLEObjects method so that I could specify a string name for each image
control and you nailed it with your solution). I appreciate the time you
took to provide this solution to me and the rest of the Excel community.

Paul Mathews

"Dave Peterson" wrote:

Option Explicit
Sub testme()
Dim iCtr As Long
For iCtr = 1 To 3
Sheet1.OLEObjects("Image" & iCtr).Object.Picture _
= LoadPicture("c:\pict" & iCtr & ".jpg")
Next iCtr
End Sub

Paul Mathews wrote:

I'm attempting to set the picture property of several image controls on a
single worksheet (not on a user form). For example, three image controls
(named Image1, Image2, and Image3) on Sheet 1:

Sheet1.Image1.Picture = LoadPicture("C:\Pic1.jpg")
Sheet1.Image2.Picture = LoadPicture("C:\Pic2.jpg")
Sheet1.Image3.Picture = LoadPicture("C:\Pic3.jpg")

Can anyone suggest a way to set the picture property for each image by
looping rather than repeating the loadpicture for each image as above?
Thanks in advance.

--

Dave Peterson


--

Dave Peterson


--

Dave Peterson
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
Image Controls Sandy[_6_] Excel Programming 2 July 2nd 05 08:15 PM
Image and WebBrowser Controls JT[_2_] Excel Programming 2 September 17th 04 08:44 PM
Image Edit and WebBrowser controls JT[_2_] Excel Programming 0 September 17th 04 06:54 PM
Loop through objects/controls on worksheet Tom V Excel Programming 2 September 16th 04 06:09 PM
Bmp vs Gif in Userform image controls Sandy-V[_2_] Excel Programming 0 January 14th 04 01:46 PM


All times are GMT +1. The time now is 02:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"