Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default Class module question

The code below is from John Walkenbach's site (j-walk.com)
It makes easy work of handling multiple UserForm Buttons with one subroutine.
I've been trying to adapt it to work with multiple image controls on a
WORKSHEET rather than a UserForm. Any advice will be much appreciated


Class1 code:
Public WithEvents ButtonGroup As CommandButton

Private Sub ButtonGroup_Click()
MsgBox "Hello from " & ButtonGroup.Name
End Sub

Module1 code:
Dim Buttons() As New Class1

UserForm1 code:
Private Sub OKButton_Click()
Unload Me
End Sub

Sub ShowDialog()
Dim ButtonCount As Integer
Dim ctl As Control

' Create the Button objects
ButtonCount = 0
For Each ctl In UserForm1.Controls
If TypeName(ctl) = "CommandButton" Then
If ctl.Name < "OKButton" Then 'Skip the OKButton
ButtonCount = ButtonCount + 1
ReDim Preserve Buttons(1 To ButtonCount)
Set Buttons(ButtonCount).ButtonGroup = ctl
End If
End If
Next ctl
UserForm1.Show
End Sub
--
David
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Class module question

Hi David,

Drop a few Image controls onto the worksheet from the Controls Toolbox menu.
Try this demo and click the images.

' in Class1
Public WithEvents img As MSForms.Image
Dim sName As String
Dim id As Long

Public Property Let propName(nID As Long, s As String)
id = nID
sName = s
End Property

Private Sub img_Click()
MsgBox "My Name " & sName & vbCr & "My Id " & id
End Sub

' end Class1


' In a normal module
Dim maImages() As New Class1

Sub Setup()
Dim oOLE As OLEObject
Dim cntImage As Long

For Each oOLE In ActiveSheet.OLEObjects
If TypeOf oOLE.Object Is MSForms.Image Then
cntImage = cntImage + 1
ReDim Preserve maImages(1 To cntImage)
Set maImages(cntImage).img = oOLE.Object
maImages(cntImage).propName(cntImage) = oOLE.Name
End If
Next

End Sub

Sub Clearup()
On Error Resume Next ' error if the array is empty
Erase maImages
End Sub

Run Clearup when done, perhaps in from Workbook close event.

Regards,
Peter T


"David" wrote in message
...
The code below is from John Walkenbach's site (j-walk.com)
It makes easy work of handling multiple UserForm Buttons with one

subroutine.
I've been trying to adapt it to work with multiple image controls on a
WORKSHEET rather than a UserForm. Any advice will be much appreciated


Class1 code:
Public WithEvents ButtonGroup As CommandButton

Private Sub ButtonGroup_Click()
MsgBox "Hello from " & ButtonGroup.Name
End Sub

Module1 code:
Dim Buttons() As New Class1

UserForm1 code:
Private Sub OKButton_Click()
Unload Me
End Sub

Sub ShowDialog()
Dim ButtonCount As Integer
Dim ctl As Control

' Create the Button objects
ButtonCount = 0
For Each ctl In UserForm1.Controls
If TypeName(ctl) = "CommandButton" Then
If ctl.Name < "OKButton" Then 'Skip the OKButton
ButtonCount = ButtonCount + 1
ReDim Preserve Buttons(1 To ButtonCount)
Set Buttons(ButtonCount).ButtonGroup = ctl
End If
End If
Next ctl
UserForm1.Show
End Sub
--
David



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default Class module question

Peter,
Thankyou so much.
You made my day with that solution, works great.
I'll save it in my reference files until I eventually become familiar with
the code methods used.
--
David


"Peter T" wrote:

Hi David,

Drop a few Image controls onto the worksheet from the Controls Toolbox menu.
Try this demo and click the images.

' in Class1
Public WithEvents img As MSForms.Image
Dim sName As String
Dim id As Long

Public Property Let propName(nID As Long, s As String)
id = nID
sName = s
End Property

Private Sub img_Click()
MsgBox "My Name " & sName & vbCr & "My Id " & id
End Sub

' end Class1


' In a normal module
Dim maImages() As New Class1

Sub Setup()
Dim oOLE As OLEObject
Dim cntImage As Long

For Each oOLE In ActiveSheet.OLEObjects
If TypeOf oOLE.Object Is MSForms.Image Then
cntImage = cntImage + 1
ReDim Preserve maImages(1 To cntImage)
Set maImages(cntImage).img = oOLE.Object
maImages(cntImage).propName(cntImage) = oOLE.Name
End If
Next

End Sub

Sub Clearup()
On Error Resume Next ' error if the array is empty
Erase maImages
End Sub

Run Clearup when done, perhaps in from Workbook close event.

Regards,
Peter T


"David" wrote in message
...
The code below is from John Walkenbach's site (j-walk.com)
It makes easy work of handling multiple UserForm Buttons with one

subroutine.
I've been trying to adapt it to work with multiple image controls on a
WORKSHEET rather than a UserForm. Any advice will be much appreciated


Class1 code:
Public WithEvents ButtonGroup As CommandButton

Private Sub ButtonGroup_Click()
MsgBox "Hello from " & ButtonGroup.Name
End Sub

Module1 code:
Dim Buttons() As New Class1

UserForm1 code:
Private Sub OKButton_Click()
Unload Me
End Sub

Sub ShowDialog()
Dim ButtonCount As Integer
Dim ctl As Control

' Create the Button objects
ButtonCount = 0
For Each ctl In UserForm1.Controls
If TypeName(ctl) = "CommandButton" Then
If ctl.Name < "OKButton" Then 'Skip the OKButton
ButtonCount = ButtonCount + 1
ReDim Preserve Buttons(1 To ButtonCount)
Set Buttons(ButtonCount).ButtonGroup = ctl
End If
End If
Next ctl
UserForm1.Show
End Sub
--
David




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Class module question

Hi David,

Glad that was useful.

Was it you who asked a while back about returning the location of an image
control when clicked - if so try this in the click event in the example I
posted:

MsgBox img.TopLeftCell.Address

Regards,
Peter T


"David" wrote in message
...
Peter,
Thankyou so much.
You made my day with that solution, works great.
I'll save it in my reference files until I eventually become familiar with
the code methods used.
--
David


"Peter T" wrote:

Hi David,

Drop a few Image controls onto the worksheet from the Controls Toolbox

menu.
Try this demo and click the images.

' in Class1
Public WithEvents img As MSForms.Image
Dim sName As String
Dim id As Long

Public Property Let propName(nID As Long, s As String)
id = nID
sName = s
End Property

Private Sub img_Click()
MsgBox "My Name " & sName & vbCr & "My Id " & id
End Sub

' end Class1


' In a normal module
Dim maImages() As New Class1

Sub Setup()
Dim oOLE As OLEObject
Dim cntImage As Long

For Each oOLE In ActiveSheet.OLEObjects
If TypeOf oOLE.Object Is MSForms.Image Then
cntImage = cntImage + 1
ReDim Preserve maImages(1 To cntImage)
Set maImages(cntImage).img = oOLE.Object
maImages(cntImage).propName(cntImage) = oOLE.Name
End If
Next

End Sub

Sub Clearup()
On Error Resume Next ' error if the array is empty
Erase maImages
End Sub

Run Clearup when done, perhaps in from Workbook close event.

Regards,
Peter T


"David" wrote in message
...
The code below is from John Walkenbach's site (j-walk.com)
It makes easy work of handling multiple UserForm Buttons with one

subroutine.
I've been trying to adapt it to work with multiple image controls on a
WORKSHEET rather than a UserForm. Any advice will be much appreciated


Class1 code:
Public WithEvents ButtonGroup As CommandButton

Private Sub ButtonGroup_Click()
MsgBox "Hello from " & ButtonGroup.Name
End Sub

Module1 code:
Dim Buttons() As New Class1

UserForm1 code:
Private Sub OKButton_Click()
Unload Me
End Sub

Sub ShowDialog()
Dim ButtonCount As Integer
Dim ctl As Control

' Create the Button objects
ButtonCount = 0
For Each ctl In UserForm1.Controls
If TypeName(ctl) = "CommandButton" Then
If ctl.Name < "OKButton" Then 'Skip the OKButton
ButtonCount = ButtonCount + 1
ReDim Preserve Buttons(1 To ButtonCount)
Set Buttons(ButtonCount).ButtonGroup = ctl
End If
End If
Next ctl
UserForm1.Show
End Sub
--
David






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default Class module question

Peter,
Yes, it was me, I am now using .topLeftCell to get the contents of cells
local to the each image control (I've got about 40 on each sheet). The local
cell info then becomes criteria for database query(s). The query feeds a
chart and the chart is displayed in a userform; ie the user clicks an image
control and gets the relevant to the location of the image info presented on
a chart. I've still got a bit to do but it's shaping up great thanks to the
help from yourself and others like you.

"Peter T" wrote:

Hi David,

Glad that was useful.

Was it you who asked a while back about returning the location of an image
control when clicked - if so try this in the click event in the example I
posted:

MsgBox img.TopLeftCell.Address

Regards,
Peter T


"David" wrote in message
...
Peter,
Thankyou so much.
You made my day with that solution, works great.
I'll save it in my reference files until I eventually become familiar with
the code methods used.
--
David


"Peter T" wrote:

Hi David,

Drop a few Image controls onto the worksheet from the Controls Toolbox

menu.
Try this demo and click the images.

' in Class1
Public WithEvents img As MSForms.Image
Dim sName As String
Dim id As Long

Public Property Let propName(nID As Long, s As String)
id = nID
sName = s
End Property

Private Sub img_Click()
MsgBox "My Name " & sName & vbCr & "My Id " & id
End Sub

' end Class1


' In a normal module
Dim maImages() As New Class1

Sub Setup()
Dim oOLE As OLEObject
Dim cntImage As Long

For Each oOLE In ActiveSheet.OLEObjects
If TypeOf oOLE.Object Is MSForms.Image Then
cntImage = cntImage + 1
ReDim Preserve maImages(1 To cntImage)
Set maImages(cntImage).img = oOLE.Object
maImages(cntImage).propName(cntImage) = oOLE.Name
End If
Next

End Sub

Sub Clearup()
On Error Resume Next ' error if the array is empty
Erase maImages
End Sub

Run Clearup when done, perhaps in from Workbook close event.

Regards,
Peter T


"David" wrote in message
...
The code below is from John Walkenbach's site (j-walk.com)
It makes easy work of handling multiple UserForm Buttons with one
subroutine.
I've been trying to adapt it to work with multiple image controls on a
WORKSHEET rather than a UserForm. Any advice will be much appreciated


Class1 code:
Public WithEvents ButtonGroup As CommandButton

Private Sub ButtonGroup_Click()
MsgBox "Hello from " & ButtonGroup.Name
End Sub

Module1 code:
Dim Buttons() As New Class1

UserForm1 code:
Private Sub OKButton_Click()
Unload Me
End Sub

Sub ShowDialog()
Dim ButtonCount As Integer
Dim ctl As Control

' Create the Button objects
ButtonCount = 0
For Each ctl In UserForm1.Controls
If TypeName(ctl) = "CommandButton" Then
If ctl.Name < "OKButton" Then 'Skip the OKButton
ButtonCount = ButtonCount + 1
ReDim Preserve Buttons(1 To ButtonCount)
Set Buttons(ButtonCount).ButtonGroup = ctl
End If
End If
Next ctl
UserForm1.Show
End Sub
--
David






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
CLASS MODULE & SIMPLE MODULE FARAZ QURESHI Excel Discussion (Misc queries) 1 September 7th 07 09:32 AM
Chart Class Module/follow on question to hyperlink post earlier. Rominall Charts and Charting in Excel 2 March 7th 07 02:43 AM
let and get in class module Doug Glancy Excel Programming 3 June 30th 04 02:30 PM
Class Module Todd Huttenstine Excel Programming 2 May 21st 04 11:17 PM
Variable from a sheet module in a class module in XL XP hglamy[_2_] Excel Programming 2 October 14th 03 05:48 PM


All times are GMT +1. The time now is 05:08 AM.

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"