Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
N+ N+ is offline
external usenet poster
 
Posts: 34
Default switching window stops running macros

hi all !
i have a cyclic vbe program that bob gave to me and it works fine..
but i need to open it in more than one windows simoultaneously, and when i
switch to window 2, the timer in the window 1 stops !!
maybe someone can suggest me how to do!
this is the code:

TIMER

Add this to a standard code module

Option Explicit

Public nTime As Double

Public Sub StartTimer()
On Error Resume Next
Application.OnTime nTime, "RunTimer", , False
On Error GoTo 0

ActiveSheet.Range("A1").Value = 0
RunTimer
End Sub

Public Sub StopTimer()
Application.OnTime nTime, "RunTimer", , False
End Sub

Public Sub RunTimer()
With ActiveSheet.Range("A1")
.Value = .Value + TimeSerial(0, 0, 1)
.NumberFormat = "hh:mm:ss"
End With
nTime = Now + TimeSerial(0, 0, 1)
Application.OnTime nTime, "RunTimer"
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default switching window stops running macros

I'm guessing it's seeing a different activesheet when you go to a different
window. You're going to have to specify the workbook and sheet you want, I
think.

Try this

Option Explicit

Public nTime As Double

Public Sub StartTimer()
Dim aWB As Workbook
Dim aWS As Worksheet

Set aWB = ThisWorkbook
Set aWS = aWB.Worksheets("Sheet1") 'change sheet name as needed
On Error Resume Next
Application.OnTime nTime, "RunTimer", , False
On Error GoTo 0

aWS.Range("A1").Value = 0
RunTimer
End Sub

Public Sub StopTimer()
Application.OnTime nTime, "RunTimer", , False
End Sub

Public Sub RunTimer()
Dim aWB As Workbook
Dim aWS As Worksheet

Set aWB = ThisWorkbook
Set aWS = aWB.Worksheets("Sheet1") 'change sheet name as needed

With aWS.Range("A1")
.Value = .Value + TimeSerial(0, 0, 1)
.NumberFormat = "hh:mm:ss"
End With
nTime = Now + TimeSerial(0, 0, 1)
Application.OnTime nTime, "RunTimer"
End Sub

--
HTH,
Barb Reinhardt



"N+" wrote:

hi all !
i have a cyclic vbe program that bob gave to me and it works fine..
but i need to open it in more than one windows simoultaneously, and when i
switch to window 2, the timer in the window 1 stops !!
maybe someone can suggest me how to do!
this is the code:

TIMER

Add this to a standard code module

Option Explicit

Public nTime As Double

Public Sub StartTimer()
On Error Resume Next
Application.OnTime nTime, "RunTimer", , False
On Error GoTo 0

ActiveSheet.Range("A1").Value = 0
RunTimer
End Sub

Public Sub StopTimer()
Application.OnTime nTime, "RunTimer", , False
End Sub

Public Sub RunTimer()
With ActiveSheet.Range("A1")
.Value = .Value + TimeSerial(0, 0, 1)
.NumberFormat = "hh:mm:ss"
End With
nTime = Now + TimeSerial(0, 0, 1)
Application.OnTime nTime, "RunTimer"
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
N+ N+ is offline
external usenet poster
 
Posts: 34
Default switching window stops running macros

ty barb i will try as soon as possible and tell u how it works !

"Barb Reinhardt" wrote:

I'm guessing it's seeing a different activesheet when you go to a different
window. You're going to have to specify the workbook and sheet you want, I
think.

Try this

Option Explicit

Public nTime As Double

Public Sub StartTimer()
Dim aWB As Workbook
Dim aWS As Worksheet

Set aWB = ThisWorkbook
Set aWS = aWB.Worksheets("Sheet1") 'change sheet name as needed
On Error Resume Next
Application.OnTime nTime, "RunTimer", , False
On Error GoTo 0

aWS.Range("A1").Value = 0
RunTimer
End Sub

Public Sub StopTimer()
Application.OnTime nTime, "RunTimer", , False
End Sub

Public Sub RunTimer()
Dim aWB As Workbook
Dim aWS As Worksheet

Set aWB = ThisWorkbook
Set aWS = aWB.Worksheets("Sheet1") 'change sheet name as needed

With aWS.Range("A1")
.Value = .Value + TimeSerial(0, 0, 1)
.NumberFormat = "hh:mm:ss"
End With
nTime = Now + TimeSerial(0, 0, 1)
Application.OnTime nTime, "RunTimer"
End Sub

--
HTH,
Barb Reinhardt



"N+" wrote:

hi all !
i have a cyclic vbe program that bob gave to me and it works fine..
but i need to open it in more than one windows simoultaneously, and when i
switch to window 2, the timer in the window 1 stops !!
maybe someone can suggest me how to do!
this is the code:

TIMER

Add this to a standard code module

Option Explicit

Public nTime As Double

Public Sub StartTimer()
On Error Resume Next
Application.OnTime nTime, "RunTimer", , False
On Error GoTo 0

ActiveSheet.Range("A1").Value = 0
RunTimer
End Sub

Public Sub StopTimer()
Application.OnTime nTime, "RunTimer", , False
End Sub

Public Sub RunTimer()
With ActiveSheet.Range("A1")
.Value = .Value + TimeSerial(0, 0, 1)
.NumberFormat = "hh:mm:ss"
End With
nTime = Now + TimeSerial(0, 0, 1)
Application.OnTime nTime, "RunTimer"
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
N+ N+ is offline
external usenet poster
 
Posts: 34
Default switching window stops running macros

hi barb it is working ok ty !!
but if i had to insert my macro , where should i put "her" for avoiding it
to run multiply in each code cycle, when i open many times the same window ?
ty!

"N+" wrote:

hi all !
i have a cyclic vbe program that bob gave to me and it works fine..
but i need to open it in more than one windows simoultaneously, and when i
switch to window 2, the timer in the window 1 stops !!
maybe someone can suggest me how to do!
this is the code:

TIMER

Add this to a standard code module

Option Explicit

Public nTime As Double

Public Sub StartTimer()
On Error Resume Next
Application.OnTime nTime, "RunTimer", , False
On Error GoTo 0

ActiveSheet.Range("A1").Value = 0
RunTimer
End Sub

Public Sub StopTimer()
Application.OnTime nTime, "RunTimer", , False
End Sub

Public Sub RunTimer()
With ActiveSheet.Range("A1")
.Value = .Value + TimeSerial(0, 0, 1)
.NumberFormat = "hh:mm:ss"
End With
nTime = Now + TimeSerial(0, 0, 1)
Application.OnTime nTime, "RunTimer"
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
N+ N+ is offline
external usenet poster
 
Posts: 34
Default switching window stops running macros

done..modified all "range" with aws.range !! ty
but i cant avoid calculatin 3 times a ccle with something else than
application.calculate !

"N+" wrote:

hi barb it is working ok ty !!
but if i had to insert my macro , where should i put "her" for avoiding it
to run multiply in each code cycle, when i open many times the same window ?
ty!

"N+" wrote:

hi all !
i have a cyclic vbe program that bob gave to me and it works fine..
but i need to open it in more than one windows simoultaneously, and when i
switch to window 2, the timer in the window 1 stops !!
maybe someone can suggest me how to do!
this is the code:

TIMER

Add this to a standard code module

Option Explicit

Public nTime As Double

Public Sub StartTimer()
On Error Resume Next
Application.OnTime nTime, "RunTimer", , False
On Error GoTo 0

ActiveSheet.Range("A1").Value = 0
RunTimer
End Sub

Public Sub StopTimer()
Application.OnTime nTime, "RunTimer", , False
End Sub

Public Sub RunTimer()
With ActiveSheet.Range("A1")
.Value = .Value + TimeSerial(0, 0, 1)
.NumberFormat = "hh:mm:ss"
End With
nTime = Now + TimeSerial(0, 0, 1)
Application.OnTime nTime, "RunTimer"
End Sub

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
why excel stops running?? usiddiqi Excel Discussion (Misc queries) 2 May 17th 06 10:14 AM
Running code/switching between sheets Metrazal[_9_] Excel Programming 7 February 24th 06 02:56 PM
Switching between sheets in same window... Kojones Excel Discussion (Misc queries) 1 July 16th 05 10:16 PM
switching from one window to another Sergiek Excel Programming 1 June 28th 05 04:44 AM
Switching to other apps while running macros in excel 97 Jon Peltier[_3_] Excel Programming 2 July 11th 03 10:49 PM


All times are GMT +1. The time now is 10:03 AM.

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

About Us

"It's about Microsoft Excel"