get all the labels of all forms in array
Need to get all the labels of all forms in an array of custom objects.
This is in connection with control specific help.
Tried like this:
In Class module:
------------------------------
Option Explicit
Public WithEvents objLabel As MSForms.Label
Private Sub objLabel_MouseDown(ByVal Button As Integer, _
ByVal Shift As Integer, _
ByVal X As Single, _
ByVal Y As Single)
Dim lContextHelpID As Long
'The following is required because the MouseDown event
'fires twice when right-clicked !!
lClassRightClickCount = lClassRightClickCount + 1
' Do nothing on second firing of MouseDown event
If (lClassRightClickCount Mod 2 = 0) Then
Exit Sub
End If
If Button = 2 Then
On Error Resume Next
lContextHelpID = objLabel.Tag
On Error GoTo 0
If lContextHelpID 0 Then
ShowHelp bWebHelp, lContextHelpID
End If
End If
End Sub
In Normal module:
--------------------------
Public Labels(241) As New LabelClass
Sub AddToLabelClass()
Dim oVBProj As VBProject
Dim oVBComp As VBComponent
Dim i As Long
Dim ctl As MSForms.Control
Set oVBProj = ThisWorkbook.VBProject
For Each oVBComp In oVBProj.VBComponents
If oVBComp.Type = 3 Then
For Each ctl In oVBComp.Designer.Controls
If TypeOf ctl Is MSForms.Label Then
Set Labels(i).objLabel = ctl
i = i + 1
End If
Next
End If
Next
End Sub
I get different error messages and it just doesn't work.
Maybe the trouble is with this:
For Each ctl In oVBComp.Designer.Controls
but haven't found another way yet.
Thanks for any assistance.
RBS
|