Pause or cancel within a loop

  • Thread starter Thread starter JeffH
  • Start date Start date
J

JeffH

I have a do loop that prints a repetitive report for a range of companies on
a specified list. The problem is that once I involke the macro to print it
goes through the entire list with no ability for me to stop it (or at least I
don't know how).

I thought I could add a MsgBox in the loop and it would cancel printing, but
it does not. It loops through, asks me the question in the msgbox, but does
not end the loop when I answer "NO".

An abreviated example of what I got going is:

Dim i As Integer
i=9
Do until ("A" & i) = "" (it stops printing when the list is empty)

(Following is the code to print the range)

MsgBox "Continue Printing?', vbOKCancel, "Printing"

i = i +1
Loop
 
I have a do loop that prints a repetitive report for a range of companieson
a specified list.  The problem is that once I involke the macro to print it
goes through the entire list with no ability for me to stop it (or at least I
don't know how).

I thought I could add a MsgBox in the loop and it would cancel printing, but
it does not.  It loops through, asks me the question in the msgbox, butdoes
not end the loop when I answer "NO".

An abreviated example of what I got going is:

Dim i As Integer
i=9
Do until ("A" & i) = ""  (it stops printing when the list is empty)

    (Following is the code to print the range)

MsgBox "Continue Printing?', vbOKCancel, "Printing"

i = i +1
Loop

You have to modify the loop a little bit...

dim intAnswer as integer
dim i as Integer

do until intAnswer=vbCancel or i=9
'code to print the range
i = i + 1
intAnswer=Msgbox("Continue Printing?",vbOKCancel, "Printing")
loop
 
Back
Top