Article ID: 181792
Article Last Modified on 6/17/2005
Sub InfiniteLoop()
Dim n As Integer
Dim strMsg As String
n = 0
strMsg = "WARNING: This macro will cause an infinite loop. " & vbCr
strMsg = strMsg & vbCr & "Press OK to continue and then press "
strMsg = strMsg & "command+.(period) to exit this infinite "
strMsg = strMsg & "loop or press Cancel to Stop this macro now."
x = MsgBox(strMsg, vbExclamation + vbOKCancel, "Warning!")
If x = vbCancel Then n = 1
Do
' Because the "Do...Loop" is looking for the value of 'n'
' to equal 1, and because there is no code within the loop
' to change the value of the variable 'n' from its initial
' value of zero, the "Do...Loop" will continue to loop
' indefinitely.
Loop Until n = 1
End Sub
163435 VBA: Programming Resources for Visual Basic for Applications
Additional query words: wordcon vb vbe vba
Keywords: kbinfo kbmacroexample kbdtacode KB181792