Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Can I run two macros in the same time?

Can I run two macros in the same time?
Thank for the help
Emil.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 400
Default Can I run two macros in the same time?


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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Can I run two macros in the same time?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Can I run two macros in the same time?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Can I run two macros in the same time?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default Can I run two macros in the same time?

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Can I run two macros in the same time?

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Time keys in macros Sudhir Amin Excel Discussion (Misc queries) 0 August 1st 07 04:36 PM
running macros at a set time Monica Excel Discussion (Misc queries) 1 December 12th 06 11:03 PM
Run two macros in the same time. emil Excel Programming 3 June 19th 06 07:41 PM
time specific macros dobson,james Excel Programming 2 August 4th 05 11:57 AM
Two Macros at the same time?? is it possible 0000_AAAA_0000[_8_] Excel Programming 4 November 11th 04 12:46 AM


All times are GMT +1. The time now is 10:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"