Moi,
Mulla on tälläinen koodi kun excelissä userform aukeaa:
Private Sub UserForm_Activate() Label17.Caption = Format(Date) Do Label18.Caption = Format(Now, "hh:mm:ss") DoEvents Loop End Sub
Ongelma on se, että kun userform suljetaan, niin sen suoritusta ei kuitenkaan lopeteta.
Eli miten saan tuon loopin loppumaan samalla kun esim painikkeesta painetaan joka sulkee lomakkeen?
Ratkaisu on varmaan ihan yksinkertainen, mutta en ole sitä keksinyt...
Kiitos!
Mod. lisäsi kooditagit.
Moi Tiri!
kokeile oheista viritelmää...
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private Sub UserForm_Activate() Static LoopExit As Boolean LoopExit = False Label17.Caption = Format(Date) Do While Not LoopExit Label18.Caption = Format(Now, "hh:mm:ss") Sleep 250 DoEvents Loop End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) LoopExit = True End Sub
Kiitän :)
Sorry Tiri!
it still hangs in the previous example...here's the right manner
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private AllowExit As Boolean 'the boolean should be declared in generals 'instead of static inside the procedure... Private Sub UserForm_Activate() AllowExit = False Label17.Caption = Format(Date) Do While Not AllowExit DoEvents Label18.Caption = Format(Now, "hh:mm:ss") Sleep 250 Loop End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) AllowExit = True End Sub
Aihe on jo aika vanha, joten et voi enää vastata siihen.