Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default BeforeClose running twice

I have the following code:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
msg = "You are attempting to manually exit a DCA file." & vbCrLf &
vbCrLf
msg = msg + "This file type should only be closed through the DCA
menu. Failure to do so risks the LOSS of data!" & vbCrLf & vbCrLf & vbCrLf
msg = msg + "Press 'Ok' to Continue" & vbCrLf & vbCrLf
msg = msg + "Press 'Cancel' to abort the file save and return to
excel." & vbCrLf & vbCrLf
Ret = MsgBox(msg, vbExclamation + vbOKCancel)
If Ret = vbOK Then
' Proceed with file closure
ElseIf Ret = vbCancel Then
Cancel = True
End If
End Sub

If I hit Cancel I get the expected result, if I hit Ok, runs through to the
End Sub and goes back up to the beginning and runs the whole macro again. So
you effectively get asked twice on closing the file.

What am I doing wrong? Any ideas welcome, thanks.

--
Trefor

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default BeforeClose running twice

Try disabling event upon entry and the re-enabling on exit.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Trefor" wrote in message
...
I have the following code:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
msg = "You are attempting to manually exit a DCA file." & vbCrLf &
vbCrLf
msg = msg + "This file type should only be closed through the DCA
menu. Failure to do so risks the LOSS of data!" & vbCrLf & vbCrLf & vbCrLf
msg = msg + "Press 'Ok' to Continue" & vbCrLf & vbCrLf
msg = msg + "Press 'Cancel' to abort the file save and return to
excel." & vbCrLf & vbCrLf
Ret = MsgBox(msg, vbExclamation + vbOKCancel)
If Ret = vbOK Then
' Proceed with file closure
ElseIf Ret = vbCancel Then
Cancel = True
End If
End Sub

If I hit Cancel I get the expected result, if I hit Ok, runs through to
the
End Sub and goes back up to the beginning and runs the whole macro again.
So
you effectively get asked twice on closing the file.

What am I doing wrong? Any ideas welcome, thanks.

--
Trefor



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default BeforeClose running twice

Bob,

Thanks for the tip, sounded good to me, but no luck.

--
Trefor


"Bob Phillips" wrote:

Try disabling event upon entry and the re-enabling on exit.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Trefor" wrote in message
...
I have the following code:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
msg = "You are attempting to manually exit a DCA file." & vbCrLf &
vbCrLf
msg = msg + "This file type should only be closed through the DCA
menu. Failure to do so risks the LOSS of data!" & vbCrLf & vbCrLf & vbCrLf
msg = msg + "Press 'Ok' to Continue" & vbCrLf & vbCrLf
msg = msg + "Press 'Cancel' to abort the file save and return to
excel." & vbCrLf & vbCrLf
Ret = MsgBox(msg, vbExclamation + vbOKCancel)
If Ret = vbOK Then
' Proceed with file closure
ElseIf Ret = vbCancel Then
Cancel = True
End If
End Sub

If I hit Cancel I get the expected result, if I hit Ok, runs through to
the
End Sub and goes back up to the beginning and runs the whole macro again.
So
you effectively get asked twice on closing the file.

What am I doing wrong? Any ideas welcome, thanks.

--
Trefor




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default BeforeClose running twice

I even tried setting a variable to track that it had already made one pass,
but at the start of the second pass the variable got set to Empty and I had
nothing to check.

--
Trefor


"Trefor" wrote:

Bob,

Thanks for the tip, sounded good to me, but no luck.

--
Trefor


"Bob Phillips" wrote:

Try disabling event upon entry and the re-enabling on exit.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Trefor" wrote in message
...
I have the following code:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
msg = "You are attempting to manually exit a DCA file." & vbCrLf &
vbCrLf
msg = msg + "This file type should only be closed through the DCA
menu. Failure to do so risks the LOSS of data!" & vbCrLf & vbCrLf & vbCrLf
msg = msg + "Press 'Ok' to Continue" & vbCrLf & vbCrLf
msg = msg + "Press 'Cancel' to abort the file save and return to
excel." & vbCrLf & vbCrLf
Ret = MsgBox(msg, vbExclamation + vbOKCancel)
If Ret = vbOK Then
' Proceed with file closure
ElseIf Ret = vbCancel Then
Cancel = True
End If
End Sub

If I hit Cancel I get the expected result, if I hit Ok, runs through to
the
End Sub and goes back up to the beginning and runs the whole macro again.
So
you effectively get asked twice on closing the file.

What am I doing wrong? Any ideas welcome, thanks.

--
Trefor




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default BeforeClose running twice

It only passes through once for me, so there must be some other code
interacting. What is in the OK action?

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Trefor" wrote in message
...
I even tried setting a variable to track that it had already made one pass,
but at the start of the second pass the variable got set to Empty and I
had
nothing to check.

--
Trefor


"Trefor" wrote:

Bob,

Thanks for the tip, sounded good to me, but no luck.

--
Trefor


"Bob Phillips" wrote:

Try disabling event upon entry and the re-enabling on exit.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Trefor" wrote in message
...
I have the following code:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
msg = "You are attempting to manually exit a DCA file." &
vbCrLf &
vbCrLf
msg = msg + "This file type should only be closed through the
DCA
menu. Failure to do so risks the LOSS of data!" & vbCrLf & vbCrLf &
vbCrLf
msg = msg + "Press 'Ok' to Continue" & vbCrLf & vbCrLf
msg = msg + "Press 'Cancel' to abort the file save and return
to
excel." & vbCrLf & vbCrLf
Ret = MsgBox(msg, vbExclamation + vbOKCancel)
If Ret = vbOK Then
' Proceed with file closure
ElseIf Ret = vbCancel Then
Cancel = True
End If
End Sub

If I hit Cancel I get the expected result, if I hit Ok, runs through
to
the
End Sub and goes back up to the beginning and runs the whole macro
again.
So
you effectively get asked twice on closing the file.

What am I doing wrong? Any ideas welcome, thanks.

--
Trefor








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default BeforeClose running twice

Bob,

Sorry what do you mean by the OK action?

--
Trefor


"Bob Phillips" wrote:

It only passes through once for me, so there must be some other code
interacting. What is in the OK action?

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"Trefor" wrote in message
...
I even tried setting a variable to track that it had already made one pass,
but at the start of the second pass the variable got set to Empty and I
had
nothing to check.

--
Trefor


"Trefor" wrote:

Bob,

Thanks for the tip, sounded good to me, but no luck.

--
Trefor


"Bob Phillips" wrote:

Try disabling event upon entry and the re-enabling on exit.

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"Trefor" wrote in message
...
I have the following code:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
msg = "You are attempting to manually exit a DCA file." &
vbCrLf &
vbCrLf
msg = msg + "This file type should only be closed through the
DCA
menu. Failure to do so risks the LOSS of data!" & vbCrLf & vbCrLf &
vbCrLf
msg = msg + "Press 'Ok' to Continue" & vbCrLf & vbCrLf
msg = msg + "Press 'Cancel' to abort the file save and return
to
excel." & vbCrLf & vbCrLf
Ret = MsgBox(msg, vbExclamation + vbOKCancel)
If Ret = vbOK Then
' Proceed with file closure
ElseIf Ret = vbCancel Then
Cancel = True
End If
End Sub

If I hit Cancel I get the expected result, if I hit Ok, runs through
to
the
End Sub and goes back up to the beginning and runs the whole macro
again.
So
you effectively get asked twice on closing the file.

What am I doing wrong? Any ideas welcome, thanks.

--
Trefor







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
beforeclose placement Curt Excel Discussion (Misc queries) 9 August 27th 07 08:00 PM
EnableEvents BeforeClose Stefi Excel Programming 2 November 16th 05 09:22 AM
BeforeClose Problem [email protected] Excel Programming 1 October 6th 05 02:15 PM
beforesave and beforeclose Adam Harding Excel Programming 2 July 25th 05 11:11 AM
BeforeClose Dilemma J. Cornor Excel Programming 0 June 21st 04 07:39 PM


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