View Full Version : How to execute a VBA program and halting another VBA code till the old program ends
bbuk9999
05-08-2016, 04:20 PM
Hi all,
How to execute a VBA program and halting another VBA code till the this program ends. Thanks in advance.
Sub Whatever()
Application.EnableEvents = False
'Code here
Application.EnableEvents = True
End sub
Paul_Hossler
05-09-2016, 09:22 AM
Hi all,
How to execute a VBA program and halting another VBA code till the this program ends. Thanks in advance.
I think a WHOLE lot more details are needed.
bbuk9999
05-09-2016, 09:34 AM
Thanks Paul,
Let's say a VBA programme is running, how to hold this programme to execute and other VBA programme within the same file. and then resume the old programme again. Thanks
Paul_Hossler
05-09-2016, 10:10 AM
How do you want to pause the first program: Hit a key, or after so many loops or seconds or what?
bbuk9999
05-09-2016, 10:20 AM
After seconds (time)
Paul_Hossler
05-09-2016, 11:05 AM
Are you lookng for something like this you mean?
Option Explicit
'pauses processing for testing
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Dim bCalledSecondAlready As Boolean
Sub FirstSub()
Dim i As Long
Dim tTimeToCallSecond As Date
tTimeToCallSecond = Time + TimeSerial(0, 0, 5) '
bCalledSecondAlready = False
For i = 1 To 10
Application.StatusBar = "First = " & i & " seconds"
Sleep 1000 ' pretend to do something
If Not bCalledSecondAlready Then
If Time > tTimeToCallSecond Then ' after 5 sec call other sub
SecondSub
End If
End If
Next i
Application.StatusBar = False
End Sub
Sub SecondSub()
Dim i As Long
bCalledSecondAlready = True
For i = 1 To 4
Application.StatusBar = "Second = " & i & " seconds"
Sleep 1000 ' pretend to do something
Next i
End Sub
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.