LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Closing running sub from a different one

I have a sub that starts a timmer and checks to see if you are there or
closes the workbook. That works great. if I close the workbook the old
fashioned way ythe CloseMe sub is still running and opens the workbook back
up. I need to put something in Sub Workbook_BeforeClose to stop the Sub
CloseMe(). I posted this earlier but it was difficult to understand waht i
was saying. i hope this is easier.

Sub Auto_Open()
LogInformation ThisWorkbook.Name & " opened by " & Application.UserName &
" " & Format(Date, "yyyy-mm-dd") & " " & Format(Time, "hh:mm")
Application.OnTime Now() + TimeValue("00:00:50"), "CloseMe"
End Sub




Public Sub CloseMe()
Dim SH As IWshRuntimeLibrary.WshShell
Dim Res As Long

Set SH = New IWshRuntimeLibrary.WshShell
Res = SH.Popup(Text:="Are you still there? Please click Yes or this file
will close in 2 minutes", secondstowait:=2, _
Title:="Active", Type:=vbYesNo)
If Res = vbYes Then
Application.OnTime Now() + TimeValue("00:00:50"), "CloseMe"
Else
Sheets("Dept. a").Visible = xlSheetVeryHidden
Sheets("Dept. b").Visible = xlSheetVeryHidden
Sheets("Dept. c").Visible = xlSheetVeryHidden
Sheets("ALL DEPARTMENT GRAPHS").Visible = xlSheetVeryHidden
Sheets("MACROS").Select
ThisWorkbook.Save
ThisWorkbook.Close
End If
End Sub

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim sht As Worksheet
Application.ScreenUpdating = False
Sheets("Dept. a").Visible = xlSheetVeryHidden
Sheets("Dept. b").Visible = xlSheetVeryHidden
Sheets("Dept. c").Visible = xlSheetVeryHidden
Sheets("ALL DEPARTMENT GRAPHS").Visible = xlSheetVeryHidden
Sheets("MACROS").Select
Application.ScreenUpdating = True
ThisWorkbook.Save
!!!!!!!!!STOP THE CLOSEME SUB!!!!!!!!
ThisWorkbook.Close
End Sub

 
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 keeps running after closing on server RB Smissaert Excel Programming 2 May 12th 08 06:29 PM
Auto running a macro on closing Jimmy D Excel Discussion (Misc queries) 6 November 22nd 07 01:58 AM
Error when closing workbooks after running .net code Stefan Hojnowski Excel Programming 1 August 6th 05 04:16 AM
Running a macro Upon Closing Confused Excel Fan Excel Programming 5 January 29th 05 11:08 AM
Closing the Userform when macro is running SuperJas Excel Programming 5 December 10th 03 05:31 AM


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

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"