Buon Giorno
Sto adattando un esercizio realizzato da Mauro Gamberini (Calendario) alle mie necessita'
cerco di utilizzarlo come Orologio .
Nella UserForm sono presenti due Frame
frOre contiene 25 Label ( Ore da 00 a 24 )
frMinuti """""""" 12 Label ( minuti da 00 a 55 )
Al Comando Click su Label il numero della stessa (Caption) viene passato ad una cella su foglio di lavoro .
Funzionano tutte meno la Label28 con Caption 00 del Frame frMinuti generando al suo Click il Blocco del Programma
(Excel Non Risponde ) con avvio della procedura di chiusura da parte di Windows
Nonostante diversi tentativi Non riesco a risolvere il problema
questo lo screenshot della UserForm in Giallo la Label Incriminata
Questo il codice
Option Explicit
Private colLabel As Collection
Private colLabel1 As Collection
Dim myLbl As clsLabel
Dim myLbl1 As clsLabel
Private Sub cbEsci_Click()
OreMinuti.Hide
End Sub
Private Sub UserForm_Initialize()
Dim ctl As MSForms.Control
Dim ctl1 As MSForms.Control
10
Set colLabel = New Collection
For Each ctl In Me.frOre.Controls
If TypeOf ctl Is MSForms.Label Then
Set myLbl = New clsLabel
Set myLbl.lbl = ctl
Set myLbl.frm = Me
colLabel.Add myLbl
End If
Next
20
Set colLabel1 = New Collection
For Each ctl1 In Me.frMinuti.Controls
If TypeOf ctl1 Is MSForms.Label Then
Set myLbl1 = New clsLabel
Set myLbl1.lbl1 = ctl1
Set myLbl1.frm = Me
colLabel1.Add myLbl1
End If
Next
End Sub
Private Sub UserForm_Terminate()
Set colLabel = Nothing
Set colLabel1 = Nothing
End Sub
Modulo di Classe
Option Explicit
Dim myLbl As clsLabel
Dim myLbl1 As clsLabel
'Dim myLbl2 As clsLabel
Private colLabel As Collection
Private colLabel1 As Collection
'Private colLabel2 As Collection
Public WithEvents lbl As MSForms.Label
Public WithEvents lbl1 As MSForms.Label
'Public WithEvents lbl2 As MSForms.Label
Public frm As UserForm
'Public frm1 As UserForm
Private Sub lbl_Click()
Dim Sh As Worksheet
Dim ctl As MSForms.Control
Dim ctl1 As MSForms.Control
10
Set colLabel = New Collection
For Each ctl In OreMinuti.frOre.Controls
If TypeOf ctl Is MSForms.Label Then
Set myLbl = New clsLabel
Set myLbl.lbl = ctl
Set myLbl.frm = OreMinuti.frOre
colLabel.Add myLbl
End If
Next
20
With Sh
ThisWorkbook.Worksheets("Foglio1").Range("A1").Value = lbl.Caption
End With
Set colLabel = Nothing
Set ctl = Nothing
End Sub
Private Sub lbl1_Click()
Dim Sh As Worksheet
Dim ctl1 As MSForms.Control
Set colLabel1 = New Collection
For Each ctl1 In OreMinuti.frMinuti.Controls
If TypeOf ctl1 Is MSForms.Label Then
Set myLbl1 = New clsLabel
Set myLbl1.lbl1 = ctl1
Set myLbl1.frm = OreMinuti.frMinuti
colLabel1.Add myLbl1
End If
Next
10
With Sh
ThisWorkbook.Worksheets("Foglio1").Range("A2").Value = lbl1.Caption
End With
Set colLabel1 = Nothing
Set ctl1 = Nothing
End Sub
'Private Sub lbl2_Click()
'Dim Sh As Worksheet
'Dim ctl2 As MSForms.Control
'Set colLabel2 = New Collection
'For Each ctl2 In frmCalendario.fraGiorni.Controls
'If TypeOf ctl2 Is MSForms.Label Then
'Set myLbl2 = New clsLabel
'Set myLbl2.lbl2 = ctl2
'Set myLbl2.frm1 = frmCalendario.fraGiorni
'colLabel2.Add myLbl2
'End If
'Next
'10
'With Sh
'ThisWorkbook.Worksheets("Foglio1").Range("A5").Value = lbl2.Caption
'End With
'Set colLabel2 = Nothing
'Set ctl2 = Nothing
'End Sub
Qualsiasi aiuto e' Gradito Grazie Claudio P