ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Application.Quit out of Do loop (https://www.excelbanter.com/excel-programming/390676-application-quit-out-do-loop.html)

JLGWhiz

Application.Quit out of Do loop
 
While doing some housekeeping on some old VBA procedures, I stumbled on this
anomaly of Application.Quit not executing out of a Do loop. Just wondered if
someone can explain why it is necessary to Exit Do before the Quit method
will execute?

Ben McBen

Application.Quit out of Do loop
 
VBA's ability, on the odd occaision, to obfuscate what must be underlying
machine code logic, to a mirage of strange magic, leaves me stunned- Just as
well we love it eh?

"JLGWhiz" wrote:

While doing some housekeeping on some old VBA procedures, I stumbled on this
anomaly of Application.Quit not executing out of a Do loop. Just wondered if
someone can explain why it is necessary to Exit Do before the Quit method
will execute?


NickHK

Application.Quit out of Do loop
 
See the difference of commenting out the DoEvents.

Private Sub CommandButton1_Click()
Dim i As Long, j As Long

For i = 1 To 100000
For j = 1 To 100000
If i = 500 And j = 1000 Then Application.Quit
Next
Debug.Print i, j
DoEvents
Next

End Sub

NickHK

"JLGWhiz" wrote in message
...
While doing some housekeeping on some old VBA procedures, I stumbled on

this
anomaly of Application.Quit not executing out of a Do loop. Just wondered

if
someone can explain why it is necessary to Exit Do before the Quit method
will execute?





All times are GMT +1. The time now is 12:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com