+ Reply to Thread
Results 1 to 4 of 4

close workbook without closing excel and stop recursive function

Hybrid View

  1. #1
    chris
    Guest

    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. #2
    Dann Pedersen
    Guest

    Re: close workbook without closing excel and stop recursive function

    "chris" <christopher.yust@gmail.com> wrote in message
    news:1151951939.500391.11880@75g2000cwc.googlegroups.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. #3
    chris
    Guest

    Re: 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" <christopher.yust@gmail.com> wrote in message
    > news:1151951939.500391.11880@75g2000cwc.googlegroups.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. #4
    chris
    Guest

    Re: 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" <christopher.yust@gmail.com> wrote in message
    > > news:1151951939.500391.11880@75g2000cwc.googlegroups.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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1