Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Can I run two macros in the same time?
Thank for the help Emil. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() If you mean can one Macro call another before it is finished, yes, try: Sub ABC() ' code XYZ 'code End Sub Sub XYZ() 'code End Sub If you mean can two macros run concurrently, the answer is no. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
AA2e72E wrote:
If you mean can one Macro call another before it is finished, yes, try: Sub ABC() ' code XYZ 'code End Sub Sub XYZ() 'code End Sub If you mean can two macros run concurrently, the answer is no. :) The answer is yes. ------------------------------------------ Module1: Sub test() UserForm1.Show UserForm2.Show Dim i As Integer For i = 1 To 10 Debug.Print "Test: " & i DoEvents Next i Unload UserForm1 Unload UserForm2 End Sub ------------------------------------------ UserForm1: Private Sub UserForm_Activate() Dim i As Integer For i = 1 To 10 Debug.Print "UserForm1: " & i DoEvents Next i End Sub ------------------------------------------ UserForm2: Private Sub UserForm_Activate() Dim i As Integer For i = 1 To 10 Debug.Print "UserForm2: " & i DoEvents Next i End Sub ------------------------------------------ In both userforms ShowModal property is set to false. Below is output. Do you see concurrency ? Test: 1 UserForm1: 1 UserForm2: 1 UserForm2: 2 UserForm2: 3 UserForm2: 4 UserForm2: 5 UserForm2: 6 UserForm2: 7 UserForm2: 8 UserForm2: 9 UserForm2: 10 UserForm1: 2 UserForm1: 3 UserForm1: 4 UserForm1: 5 UserForm1: 6 UserForm1: 7 UserForm1: 8 UserForm1: 9 UserForm1: 10 Test: 2 Test: 3 Test: 4 Test: 5 Test: 6 Test: 7 Test: 8 Test: 9 Test: 10 Windows in its nature is multithreading, so if you are able to split macors into different threads it can be multithreading. I don't know how much it is usefull in practice. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thank. Now, I have many options from you which I can try. Right, I can
consider you my unseen friends. Best regards for all. Emil "witek" a scris: AA2e72E wrote: If you mean can one Macro call another before it is finished, yes, try: Sub ABC() ' code XYZ 'code End Sub Sub XYZ() 'code End Sub If you mean can two macros run concurrently, the answer is no. :) The answer is yes. ------------------------------------------ Module1: Sub test() UserForm1.Show UserForm2.Show Dim i As Integer For i = 1 To 10 Debug.Print "Test: " & i DoEvents Next i Unload UserForm1 Unload UserForm2 End Sub ------------------------------------------ UserForm1: Private Sub UserForm_Activate() Dim i As Integer For i = 1 To 10 Debug.Print "UserForm1: " & i DoEvents Next i End Sub ------------------------------------------ UserForm2: Private Sub UserForm_Activate() Dim i As Integer For i = 1 To 10 Debug.Print "UserForm2: " & i DoEvents Next i End Sub ------------------------------------------ In both userforms ShowModal property is set to false. Below is output. Do you see concurrency ? Test: 1 UserForm1: 1 UserForm2: 1 UserForm2: 2 UserForm2: 3 UserForm2: 4 UserForm2: 5 UserForm2: 6 UserForm2: 7 UserForm2: 8 UserForm2: 9 UserForm2: 10 UserForm1: 2 UserForm1: 3 UserForm1: 4 UserForm1: 5 UserForm1: 6 UserForm1: 7 UserForm1: 8 UserForm1: 9 UserForm1: 10 Test: 2 Test: 3 Test: 4 Test: 5 Test: 6 Test: 7 Test: 8 Test: 9 Test: 10 Windows in its nature is multithreading, so if you are able to split macors into different threads it can be multithreading. I don't know how much it is usefull in practice. |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
No. I do not see concurrency. I see one process start another process. That
process completes and then the original process continues. No multi-threading. No instances of both processes running at the same time writing to the immedaite window. -- HTH... Jim Thomlinson "witek" wrote: AA2e72E wrote: If you mean can one Macro call another before it is finished, yes, try: Sub ABC() ' code XYZ 'code End Sub Sub XYZ() 'code End Sub If you mean can two macros run concurrently, the answer is no. :) The answer is yes. ------------------------------------------ Module1: Sub test() UserForm1.Show UserForm2.Show Dim i As Integer For i = 1 To 10 Debug.Print "Test: " & i DoEvents Next i Unload UserForm1 Unload UserForm2 End Sub ------------------------------------------ UserForm1: Private Sub UserForm_Activate() Dim i As Integer For i = 1 To 10 Debug.Print "UserForm1: " & i DoEvents Next i End Sub ------------------------------------------ UserForm2: Private Sub UserForm_Activate() Dim i As Integer For i = 1 To 10 Debug.Print "UserForm2: " & i DoEvents Next i End Sub ------------------------------------------ In both userforms ShowModal property is set to false. Below is output. Do you see concurrency ? Test: 1 UserForm1: 1 UserForm2: 1 UserForm2: 2 UserForm2: 3 UserForm2: 4 UserForm2: 5 UserForm2: 6 UserForm2: 7 UserForm2: 8 UserForm2: 9 UserForm2: 10 UserForm1: 2 UserForm1: 3 UserForm1: 4 UserForm1: 5 UserForm1: 6 UserForm1: 7 UserForm1: 8 UserForm1: 9 UserForm1: 10 Test: 2 Test: 3 Test: 4 Test: 5 Test: 6 Test: 7 Test: 8 Test: 9 Test: 10 Windows in its nature is multithreading, so if you are able to split macors into different threads it can be multithreading. I don't know how much it is usefull in practice. |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Jim Thomlinson wrote:
No. I do not see concurrency. I see one process start another process. That process completes and then the original process continues. No multi-threading. No instances of both processes running at the same time writing to the immedaite window. Right, but let's try something else userform2 is run as "background" process printing something on a screen from time to time. ------------------------------------ Private Sub UserForm_Activate() Dim i As Long For i = 1 To 1000000 If i Mod 10000 = 0 Then Debug.Print "UserForm2: " & i DoEvents Next i End Sub -------------------------------------- Action in userform1 is triggered by user. I moved it to Click event. Private Sub UserForm_Click() Dim i As Integer For i = 1 To 10 Debug.Print "UserForm1: " & i DoEvents Next i End Sub -------------------------------------- And these are results. Test: 1 UserForm2: 10000 UserForm2: 20000 UserForm2: 30000 UserForm2: 40000 UserForm2: 50000 UserForm2: 60000 UserForm2: 70000 UserForm2: 80000 UserForm2: 90000 UserForm2: 100000 UserForm2: 110000 UserForm1: 1 UserForm1: 2 UserForm1: 3 UserForm1: 4 UserForm1: 5 UserForm1: 6 UserForm1: 7 UserForm1: 8 UserForm1: 9 UserForm1: 10 UserForm2: 120000 UserForm2: 130000 UserForm2: 140000 UserForm1: 1 UserForm1: 2 UserForm1: 3 UserForm1: 4 UserForm1: 5 UserForm1: 6 UserForm1: 7 UserForm1: 8 UserForm1: 9 UserForm1: 10 UserForm2: 150000 UserForm2: 160000 .. .. .. UserForm2 is interrupted by UserForm1, which can be a solution for that problem if we can somehow trigger event from UserForm1. I never said that I guarantee not starving. |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
But you never can get two threads of exectution to run concurrently. I agree
that you can interup the flow of execution to allow another process to run but you can not get both processes going at the same time. There is just one thread. It might be running this process or it might be running that process but there is never more than one thread. In order to get true multi-threading you need to move up to C/C++ or a similar language. VB just won't cut it. -- HTH... Jim Thomlinson "witek" wrote: Jim Thomlinson wrote: No. I do not see concurrency. I see one process start another process. That process completes and then the original process continues. No multi-threading. No instances of both processes running at the same time writing to the immedaite window. Right, but let's try something else userform2 is run as "background" process printing something on a screen from time to time. ------------------------------------ Private Sub UserForm_Activate() Dim i As Long For i = 1 To 1000000 If i Mod 10000 = 0 Then Debug.Print "UserForm2: " & i DoEvents Next i End Sub -------------------------------------- Action in userform1 is triggered by user. I moved it to Click event. Private Sub UserForm_Click() Dim i As Integer For i = 1 To 10 Debug.Print "UserForm1: " & i DoEvents Next i End Sub -------------------------------------- And these are results. Test: 1 UserForm2: 10000 UserForm2: 20000 UserForm2: 30000 UserForm2: 40000 UserForm2: 50000 UserForm2: 60000 UserForm2: 70000 UserForm2: 80000 UserForm2: 90000 UserForm2: 100000 UserForm2: 110000 UserForm1: 1 UserForm1: 2 UserForm1: 3 UserForm1: 4 UserForm1: 5 UserForm1: 6 UserForm1: 7 UserForm1: 8 UserForm1: 9 UserForm1: 10 UserForm2: 120000 UserForm2: 130000 UserForm2: 140000 UserForm1: 1 UserForm1: 2 UserForm1: 3 UserForm1: 4 UserForm1: 5 UserForm1: 6 UserForm1: 7 UserForm1: 8 UserForm1: 9 UserForm1: 10 UserForm2: 150000 UserForm2: 160000 .. .. .. UserForm2 is interrupted by UserForm1, which can be a solution for that problem if we can somehow trigger event from UserForm1. I never said that I guarantee not starving. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Time keys in macros | Excel Discussion (Misc queries) | |||
running macros at a set time | Excel Discussion (Misc queries) | |||
Run two macros in the same time. | Excel Programming | |||
time specific macros | Excel Programming | |||
Two Macros at the same time?? is it possible | Excel Programming |