Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Question about auto_close

Hello:

I have a auto_close routine in my VBA project that
initiates when the user tries to close the file either
intentionaly or by accident.

If the closure is accidental I would like to cancel file
closure. Is there an easy way to do this?

here is the current code:

Sub auto_close()

'Declare variables
Dim intResponse As Integer
Dim strDatestamp, strPath As String

'Check to confirm file exit
intResponse = MsgBox("Are you sure you wish to Exit?",
vbYesNo)

If intResponse = 6 Then
ThisWorkbook.SaveAs Filename:=ABC.xls
else
'?????? CANCEL CLOSURE]
end if
end sub

Your help is appreciated.

Thanks,
-Neil

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Question about auto_close

Neil,

Use Workbook BeforeClose

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Declare variables
Dim intResponse As Integer
Dim strDatestamp, strPath As String

'Check to confirm file exit
intResponse = MsgBox("Are you sure you wish to Exit?", vbYesNo)

If intResponse = vbYes Then
ThisWorkbook.SaveAs Filename:=ABC.xls
Else
Cancel = True
End If

End Sub

Put it in ThisWorkbook code module.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Neil" wrote in message
...
Hello:

I have a auto_close routine in my VBA project that
initiates when the user tries to close the file either
intentionaly or by accident.

If the closure is accidental I would like to cancel file
closure. Is there an easy way to do this?

here is the current code:

Sub auto_close()

'Declare variables
Dim intResponse As Integer
Dim strDatestamp, strPath As String

'Check to confirm file exit
intResponse = MsgBox("Are you sure you wish to Exit?",
vbYesNo)

If intResponse = 6 Then
ThisWorkbook.SaveAs Filename:=ABC.xls
else
'?????? CANCEL CLOSURE]
end if
end sub

Your help is appreciated.

Thanks,
-Neil



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Question about auto_close

Correct me if I'm wrong about this, but I thought that by
the time Auto_Close runs, the workbook is already closed or
is in the process of closing.
-----Original Message-----
Hello:

I have a auto_close routine in my VBA project that
initiates when the user tries to close the file either
intentionaly or by accident.

If the closure is accidental I would like to cancel file
closure. Is there an easy way to do this?

here is the current code:

Sub auto_close()

'Declare variables
Dim intResponse As Integer
Dim strDatestamp, strPath As String

'Check to confirm file exit
intResponse = MsgBox("Are you sure you wish to Exit?",
vbYesNo)

If intResponse = 6 Then
ThisWorkbook.SaveAs Filename:=ABC.xls
else
'?????? CANCEL CLOSURE]
end if
end sub

Your help is appreciated.

Thanks,
-Neil

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 45
Default Question about auto_close

Instead of an Auto_Close routine, put your code in the Workbook_BeforeClose
event code in the Thisworkbook module. Workbook_BeforeClose has an argument,
Cancel. If you set it to TRUE, the closure will be cancelled.


On Wed, 7 Jul 2004 11:59:39 -0700, "Neil" wrote:

Hello:

I have a auto_close routine in my VBA project that
initiates when the user tries to close the file either
intentionaly or by accident.

If the closure is accidental I would like to cancel file
closure. Is there an easy way to do this?

here is the current code:

Sub auto_close()

'Declare variables
Dim intResponse As Integer
Dim strDatestamp, strPath As String

'Check to confirm file exit
intResponse = MsgBox("Are you sure you wish to Exit?",
vbYesNo)

If intResponse = 6 Then
ThisWorkbook.SaveAs Filename:=ABC.xls
else
'?????? CANCEL CLOSURE]
end if
end sub

Your help is appreciated.

Thanks,
-Neil


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
Starting Auto_Close macro based on an IF statement questor Excel Discussion (Misc queries) 4 February 25th 08 10:22 PM
unable to close macro using auto_close or application.quit gloria Excel Programming 1 January 14th 04 07:50 AM
BeforeClose, Auto_Close, and ActiveX Server Don Wiss Excel Programming 0 November 21st 03 12:21 AM
Auto_Close() needs help Phil Hageman[_3_] Excel Programming 3 November 19th 03 05:56 PM
Auto_Close Luc Benninger Excel Programming 2 October 14th 03 12:34 PM


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