2012-08-30 26 views
79

Estoy usando un While ... Wend loop de VBA.Salir de un tiempo ... Wend loop

Dim count as Integer 

While True 
    count=count+1 

    If count = 10 Then 
     ''What should be the statement to break the While...Wend loop? 
     ''Break or Exit While not working 
    EndIf 
Wend 

no quiero utilizar condición como `Mientras contar < = 10 ... Wend

Respuesta

141

A While/Wend sólo puede ser salido prematuramente con un GOTO o saliendo de un bloque exterior (Exit sub/function/another exitable loop)

Cambio a Do bucle intead;

Do While True 
    count = count + 1 

    If count = 10 Then 
     Exit Do 
    End If 
Loop 

(O para recorrer con un conjunto aumentando la variable de control)

for count = 1 to 10 
    msgbox count 
next