Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default close distinct workbook

Hi All,
I have a workbook that has a timer to close itself. the problem is that it
closes all other open workbooks!!!
Here is the code:
on 'Thisworkbook' : Call StartTimer
here is the code inside a module:

Public Declare Function SetTimer Lib "user32" ( _
ByVal HWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" ( _
ByVal HWnd As Long, ByVal nIDEvent As Long) As Long

Public TimerID As Long
Public TimerSeconds As Single

Sub StartTimer()
If Sheets("Menu").Range("B39").Value < 0 Then
TimerSeconds = Sheets("Menu").Range("B39").Value * 60
Else
TimerSeconds = 1000 ' how often to "pop" the timer.
End If
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProc)
End Sub

Sub EndTimer()
On Error Resume Next
KillTimer 0&, TimerID
Workbooks("theone.xls").Close savechanges:=False
End Sub

Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, _
ByVal nIDEvent As Long, ByVal dwTimer As Long)
CurrWB = ThisWorkbook.Name
Call EndTimer
End Sub


Any suggestions?
Thanks a lot in advance
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default close distinct workbook

It is probably failing, and thus shutting Excel down. If you have Option
Explicit the non-dimensioned variable CurrWB will cause this.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Lp12" wrote in message
...
Hi All,
I have a workbook that has a timer to close itself. the problem is that it
closes all other open workbooks!!!
Here is the code:
on 'Thisworkbook' : Call StartTimer
here is the code inside a module:

Public Declare Function SetTimer Lib "user32" ( _
ByVal HWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" ( _
ByVal HWnd As Long, ByVal nIDEvent As Long) As Long

Public TimerID As Long
Public TimerSeconds As Single

Sub StartTimer()
If Sheets("Menu").Range("B39").Value < 0 Then
TimerSeconds = Sheets("Menu").Range("B39").Value * 60
Else
TimerSeconds = 1000 ' how often to "pop" the timer.
End If
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProc)
End Sub

Sub EndTimer()
On Error Resume Next
KillTimer 0&, TimerID
Workbooks("theone.xls").Close savechanges:=False
End Sub

Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, _
ByVal nIDEvent As Long, ByVal dwTimer As Long)
CurrWB = ThisWorkbook.Name
Call EndTimer
End Sub


Any suggestions?
Thanks a lot in advance



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default close distinct workbook

Thanks a lot Bob....
I didn't quite get your response.. I've deleted the CurrWB object and gave
an hardcoded workbook 'theone.xls' .
Here is the updated code:

Public Declare Function SetTimer Lib "user32" ( _
ByVal HWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" ( _
ByVal HWnd As Long, ByVal nIDEvent As Long) As Long

Public TimerID As Long
Public TimerSeconds As Single

Sub StartTimer()
If Sheets("Menu").Range("B39").Value < 0 Then
TimerSeconds = Sheets("Menu").Range("B39").Value * 60
Else
TimerSeconds = 1000 ' how often to "pop" the timer.
End If
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProc)
End Sub

Sub EndTimer()
On Error Resume Next
KillTimer 0&, TimerID
Workbooks("theone.xls").Close savechanges:=False
End Sub

Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, _
ByVal nIDEvent As Long, ByVal dwTimer As Long)
Call EndTimer
Workbooks("theone.xls").Close savechanges:=False
End Sub


Thanks a lot,
Assaf

"Bob Phillips" wrote:

It is probably failing, and thus shutting Excel down. If you have Option
Explicit the non-dimensioned variable CurrWB will cause this.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Lp12" wrote in message
...
Hi All,
I have a workbook that has a timer to close itself. the problem is that it
closes all other open workbooks!!!
Here is the code:
on 'Thisworkbook' : Call StartTimer
here is the code inside a module:

Public Declare Function SetTimer Lib "user32" ( _
ByVal HWnd As Long, ByVal nIDEvent As Long, _
ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" ( _
ByVal HWnd As Long, ByVal nIDEvent As Long) As Long

Public TimerID As Long
Public TimerSeconds As Single

Sub StartTimer()
If Sheets("Menu").Range("B39").Value < 0 Then
TimerSeconds = Sheets("Menu").Range("B39").Value * 60
Else
TimerSeconds = 1000 ' how often to "pop" the timer.
End If
TimerID = SetTimer(0&, 0&, TimerSeconds * 1000&, AddressOf TimerProc)
End Sub

Sub EndTimer()
On Error Resume Next
KillTimer 0&, TimerID
Workbooks("theone.xls").Close savechanges:=False
End Sub

Sub TimerProc(ByVal HWnd As Long, ByVal uMsg As Long, _
ByVal nIDEvent As Long, ByVal dwTimer As Long)
CurrWB = ThisWorkbook.Name
Call EndTimer
End Sub


Any suggestions?
Thanks a lot in advance




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
Close workbook Lp12 Excel Programming 1 July 5th 06 09:09 AM
Help on Workbook close and workbook save events Adam Harding Excel Programming 1 September 29th 05 04:12 PM
Close Workbook Mike Jenkins Excel Programming 1 May 3rd 05 12:48 PM
Close a the current workbook and load another specified workbook Adrian[_7_] Excel Programming 4 August 7th 04 05:29 PM
cannot close workbook chrisneill Excel Programming 3 July 13th 03 11:10 PM


All times are GMT +1. The time now is 04:51 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"