Stop running macro button, like Ctrl-Break button
Hi Ron,
I tried your code but there seemed to be a problem with;
Sub pcdRunNextProcess(Optional ByVal l_bolSchedule = True)
Application.OnTime m_dteNextTimeToRunNextProcedure, _
m_strNextProcedureToRun As String, _
m_dteNextTimeToRunNextProcedure + VBA.TimeValue("00:00:05"),
l_bolSchedule
End Sub
I'm getting an expected end of statement msg next to As.
I'm I missing () or ""?
Thanks for you help.
"Ronald R. Dodge, Jr." wrote:
I'm not sure what your Pause method is doing specifically, but regardless,
cause of the fact that VBA is considered to be in "RUN" mode with your
current code during this entire time period, your other command buttons
among other things are disabled. By transition to using the method that I
have proposed to you to use in place of your code, the only time when VBA is
in "RUN" mode is when it's in actual execution. When it's in between
procedures, it is NOT in "RUN" mode, so the buttons on the toolbars are
enabled once again. All you would have to do is assign your Break button to
the procedure of "pcdCancelNextProcedure" method.
--
Thanks,
Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
"h2fcell" wrote in message
...
Hi Ron,
My Pause() sub uses the Timer function. My issue is getting the
SlideShow()
macro to break using an icon in the -Quick Access Toolbar-.
Thanks.
"Ronald R. Dodge, Jr." wrote:
Instead of using Pause, you may want to use Application.OnTime command.
This will mean you will need to setup multiple Subs (One for each
worksheet). See example below that replaces your code:
Dim m_strNextProcedureToRun As String, m_dteNextTimeToRunNextProcedure As
Date
Sub pcdSlideShow()
Worksheets(Array(1, 2, 3, 4, 5, 6, 7, 8)).Select
ActiveWindow.DisplayWorkbookTabs = False
ActiveWindow.DisplayHeadings = False 'Remove Row & Column headings
Application.DisplayFormulaBar = False
m_strNextProcedureToRun = "pcdShowSheet1"
m_dteNextTimeToRunNextProcedure = Now + VBA.TimeValue("00:00:01")
pcdRunNextProcess
End Sub
Sub pcdShowSheet1()
If Worksheets("TOTAL").Range("C42").Value2 < 39 Then
Refresh
Sheets("Sheet1").Select
Range("A1").Select
m_strNextProcedureToRun = "pcdShowSheet2"
m_dteNextTimeToRunNextProcedure = Now + VBA.TimeValue("00:00:05")
pcdRunNextProcess
End If
End Sub
Sub pcdShowSheet2()
Refresh
Sheets("Sheet2").Select
Range("A1").Select
m_strNextProcedureToRun = "pcdShowSheet3"
m_dteNextTimeToRunNextProcedure = Now + VBA.TimeValue("00:00:05")
pcdRunNextProcess
End Sub
Sub pcdShowSheet3()
Refresh
Sheets("Sheet3").Select
Range("A1").Select
m_strNextProcedureToRun = "pcdShowSheet4"
m_dteNextTimeToRunNextProcedure = Now + VBA.TimeValue("00:00:05")
pcdRunNextProcess
End Sub
Sub pcdShowSheet4()
Refresh
Sheets("Sheet4").Select
Range("A1").Select
m_strNextProcedureToRun = "pcdShowSheet5"
m_dteNextTimeToRunNextProcedure = Now + VBA.TimeValue("00:00:05")
pcdRunNextProcess
End Sub
Sub pcdShowSheet5()
Refresh
Sheets("Sheet5").Select
Range("A1").Select
m_strNextProcedureToRun = "pcdShowSheet6"
m_dteNextTimeToRunNextProcedure = Now + VBA.TimeValue("00:00:05")
pcdRunNextProcess
End Sub
Sub pcdShowSheet6()
Refresh
Sheets("Sheet6").Select
Range("A1").Select
m_strNextProcedureToRun = "pcdShowSheet7"
m_dteNextTimeToRunNextProcedure = Now + VBA.TimeValue("00:00:05")
pcdRunNextProcess
End Sub
Sub pcdShowSheet7()
Refresh
Sheets("Sheet7").Select
Range("A1").Select
m_strNextProcedureToRun = "pcdShowSheet8"
m_dteNextTimeToRunNextProcedure = Now + VBA.TimeValue("00:00:05")
pcdRunNextProcess
End Sub
Sub pcdShowSheet8()
Refresh
Sheets("Sheet8").Select
Range("A1").Select
m_strNextProcedureToRun = "pcdShowSheet1"
m_dteNextTimeToRunNextProcedure = Now + VBA.TimeValue("00:00:05")
pcdRunNextProcess
End Sub
Sub pcdRunNextProcess(Optional ByVal l_bolSchedule = True)
Application.OnTime m_dteNextTimeToRunNextProcedure,
m_strNextProcedureToRun As String, _
m_dteNextTimeToRunNextProcedure + VBA.TimeValue("00:00:05"),
l_bolSchedule
End Sub
Sub pcdCancelNextProcedure()
pcdRunNextProcess False
End Sub
--
Thanks,
Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
"h2fcell" wrote in message
...
Hello,
I have a button on the "Quick Access Toolbar" of an Excel 2007 workbook
that
starts a slide show and loops through 8 sheets continuously until a
linked
cell equals 39. I would like to add another button to the "Quick
Access
Toolbar" that stops the running slide show like Ctrl-Break does without
the
Visual Basic window popping up with the message "Code execution has
been
interrupted".
Any suggestions?
Below is my code.
Sub SlideShow()
Worksheets(Array(1, 2, 3, 4, 5, 6, 7, 8)).Select
ActiveWindow.DisplayWorkbookTabs = False
ActiveWindow.DisplayHeadings = False 'Remove Row & Column
headings
Application.DisplayFormulaBar = False
Do While Worksheets("TOTAL").Range("C42").Value < 39
Refresh
Sheets("Sheet1").Select
Range("A1").Select
Pause
Refresh
Sheets("Sheet2").Select
Range("A1").Select
Pause
Refresh
Sheets("Sheet3").Select
Range("A1").Select
Pause
Refresh
Sheets("Sheet4").Select
Range("A1").Select
Pause
Refresh
Sheets("Sheet5").Select
Range("A1").Select
Pause
Refresh
Sheets("Sheet6").Select
Range("A1").Select
Pause
Refresh
Sheets("Sheet7").Select
Range("A1").Select
Pause
Refresh
Sheets("TOTAL").Select
Range("A1").Select
Pause
Loop
End Sub
|