Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 17
Default close workbook without closing excel and stop recursive function

I earlier implemented a feature in one macro to allow blinking text.
The code is as follows:

Sub StartBlink()
Range("A1").Font.ColorIndex = RandomNumber(2, 56)
'Pauses it by a second
RunWhen = Now + TimeSerial(0, 0, 1)

'Restarts the function
Application.OnTime RunWhen, "StartBlink", , True
End Sub

Sub StopBlink()
Range("A1").Font.ColorIndex = xlColorIndexAutomatic

'Breaks the StartBlink function from continuing to run
Application.OnTime RunWhen, "StartBlink", , False
End Sub

I have the following code that calls the functions upon workbook open
and close in the This Workbook sheet:

Private Sub Workbook_Open()
'Opens the StartBlink function when the file opens
StartBlink
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Stops the Stopblink function to prevent error message upon exit

StopBlink

End Sub

This seemed to work great until I added a button to save and close and
prompt users if they wanted to exit excel entirely or just close the
workbook:

Private Sub CommandButton2_Click()
'Changes Caption back to "Stop Blink" for next time
CommandButton1.Caption = "Stop Blink"

'Saves Workbook
ActiveWorkbook.Save

'Prompts if you want to close Excel entirely or just close the
current window you are in
If MsgBox("Do you want to exit Excel?", vbYesNo, "Exit Microsoft
Excel") = vbYes Then
Application.Quit
Else
Workbooks("Wedding List.xls").Close
End If
End Sub

If they choose to not exit excel, it appears to close the workbook.
However, it just reopens the workbook a second later when it apparently
calls the StartBlink function again. Anyway to modify some of this
code to allow users to close the workbook for good without closing any
other excel windows? Thanks in advance!

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 9
Default close workbook without closing excel and stop recursive function

"chris" wrote in message
ps.com...
<SNIP some VBA code
However, it just reopens the workbook a second later when it apparently
calls the StartBlink function again. Anyway to modify some of this
code to allow users to close the workbook for good without closing any
other excel windows? Thanks in advance!


Do you happen to have the code in the workbook you close?

/Dann


  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 17
Default close workbook without closing excel and stop recursive function

Yeah. The actual functions are in the modules associated with the
workbook and the function that starts and stops it is in the This
Workbook sheet associated with this project. Why?


Dann Pedersen wrote:
"chris" wrote in message
ps.com...
<SNIP some VBA code
However, it just reopens the workbook a second later when it apparently
calls the StartBlink function again. Anyway to modify some of this
code to allow users to close the workbook for good without closing any
other excel windows? Thanks in advance!


Do you happen to have the code in the workbook you close?

/Dann


  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 17
Default close workbook without closing excel and stop recursive function

I fixed the problem by moving the stop and start function from Private
in this workbook to public in the module. Not sure why that fixes it,
but seems to work now.


chris wrote:
Yeah. The actual functions are in the modules associated with the
workbook and the function that starts and stops it is in the This
Workbook sheet associated with this project. Why?


Dann Pedersen wrote:
"chris" wrote in message
ps.com...
<SNIP some VBA code
However, it just reopens the workbook a second later when it apparently
calls the StartBlink function again. Anyway to modify some of this
code to allow users to close the workbook for good without closing any
other excel windows? Thanks in advance!


Do you happen to have the code in the workbook you close?

/Dann


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
Excel 2003 FAILS, but Excel 2000 SUCCEEDS ??? Richard Excel Discussion (Misc queries) 2 May 13th 23 11:46 AM
How to stop Excel remembering/loading macro from previously opened Workbook Norman Yuan Excel Discussion (Misc queries) 4 June 17th 06 04:13 PM
How do I stop Excel from closing the open file each time I open a. Welsin Setting up and Configuration of Excel 3 January 8th 05 11:16 PM
Stubborn toolbars in Excel 007 Excel Discussion (Misc queries) 9 December 11th 04 02:02 PM
How do I stop the autopaste function in Excel? Jules Excel Worksheet Functions 1 November 1st 04 09:54 PM


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

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"