Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Click to Add Image

I have a userform with 10 images that are all not visible when the userform
is loaded. I have a command button that will make each image visible each
time the button is clicked. For instance, if the button is clicked one time,
Image1 becomes Visible. If the button is clicked again, then Image2 becomes
visible, and so on. I cannot figure out how to do this. Can anyone help me?
Thank you.

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200705/1

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Click to Add Image

I added 10 images to a userform.

I named them Image1, Image2, ..., Image10.

Then I used this code behind the userform:

Option Explicit
Dim pCtr As Long
Private Sub CommandButton1_Click()
Dim iCtr As Long

If pCtr = 10 Then
pCtr = 1
Else
pCtr = pCtr + 1
End If

For iCtr = 1 To 10
Me.Controls("Image" & iCtr).Visible = CBool(iCtr = pCtr)
Next iCtr
End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
For iCtr = 1 To 10
Me.Controls("image" & iCtr).Visible = False
Next iCtr
pCtr = 10 'next will be 1
End Sub



"mtm4300 via OfficeKB.com" wrote:

I have a userform with 10 images that are all not visible when the userform
is loaded. I have a command button that will make each image visible each
time the button is clicked. For instance, if the button is clicked one time,
Image1 becomes Visible. If the button is clicked again, then Image2 becomes
visible, and so on. I cannot figure out how to do this. Can anyone help me?
Thank you.

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200705/1


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 43
Default Click to Add Image

This works great.
Is there any way when another Image is added, that the previous Image is kept
visible. For instance, If the button is clicked 2 Times, Image1 (which became
visible after 1 click) and Image2 are both visible.

Dave Peterson wrote:
I added 10 images to a userform.

I named them Image1, Image2, ..., Image10.

Then I used this code behind the userform:

Option Explicit
Dim pCtr As Long
Private Sub CommandButton1_Click()
Dim iCtr As Long

If pCtr = 10 Then
pCtr = 1
Else
pCtr = pCtr + 1
End If

For iCtr = 1 To 10
Me.Controls("Image" & iCtr).Visible = CBool(iCtr = pCtr)
Next iCtr
End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
For iCtr = 1 To 10
Me.Controls("image" & iCtr).Visible = False
Next iCtr
pCtr = 10 'next will be 1
End Sub

I have a userform with 10 images that are all not visible when the userform
is loaded. I have a command button that will make each image visible each

[quoted text clipped - 6 lines]
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200705/1



--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200705/1

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Click to Add Image

And after 10 clicks nothing changes??????

Option Explicit
Dim pCtr As Long
Private Sub CommandButton1_Click()
Dim iCtr As Long

If pCtr = 10 Then
'do nothing
Else
pCtr = pCtr + 1
End If

For iCtr = 1 To 10
Me.Controls("Image" & iCtr).Visible = CBool(iCtr <= pCtr)
Next iCtr
End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
For iCtr = 1 To 10
Me.Controls("image" & iCtr).Visible = False
Next iCtr
pCtr = 0 'next will be 1
End Sub


"mtm4300 via OfficeKB.com" wrote:

This works great.
Is there any way when another Image is added, that the previous Image is kept
visible. For instance, If the button is clicked 2 Times, Image1 (which became
visible after 1 click) and Image2 are both visible.

Dave Peterson wrote:
I added 10 images to a userform.

I named them Image1, Image2, ..., Image10.

Then I used this code behind the userform:

Option Explicit
Dim pCtr As Long
Private Sub CommandButton1_Click()
Dim iCtr As Long

If pCtr = 10 Then
pCtr = 1
Else
pCtr = pCtr + 1
End If

For iCtr = 1 To 10
Me.Controls("Image" & iCtr).Visible = CBool(iCtr = pCtr)
Next iCtr
End Sub
Private Sub UserForm_Initialize()
Dim iCtr As Long
For iCtr = 1 To 10
Me.Controls("image" & iCtr).Visible = False
Next iCtr
pCtr = 10 'next will be 1
End Sub

I have a userform with 10 images that are all not visible when the userform
is loaded. I have a command button that will make each image visible each

[quoted text clipped - 6 lines]
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200705/1



--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200705/1


--

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
MouseMove & Click event over an image control furbiuzzu Excel Programming 1 June 30th 06 09:46 AM
VBA to display image on a form - image is defined in Range Name Tan Excel Programming 4 May 17th 06 03:37 PM
How do i insert a image to a single cell then click on the cell & Geek Setting up and Configuration of Excel 1 April 28th 06 03:46 AM
Image Click Invokes Picture Toolbar Sunbank Excel Programming 0 January 16th 06 03:14 AM
Click on Image Control disables it Wexler Excel Programming 0 October 7th 03 05:35 PM


All times are GMT +1. The time now is 11:29 AM.

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"