Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Exit Menu Troubles

I am in the process of creating an "exit menu" that triggers on the
"before_close" event on the workbook. The menu itself is fairly simple
offering 4 buttons:

1. Email spreadsheet
2. Save spreadsheet
3. Return to the worksheet
4. Exit the worksheet

The email, save, and exit buttons work fine. The trouble that I am having is
the "Return to worksheet" button.

I have tried the following code:

Private Sub ReturnButton_Click()
Cancel = True
Unload ExitOptions
Application.ExecuteExcel4Macro "HALT(True)"
End Sub

If I try to cancel the exit, the sheet still closes. I can't seem to get it
to return an halt the closing process.

I have tried quite a few permutations, but still nada,

Any suggestions?

WillRn
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Exit Menu Troubles

Will,

Cancel is not a global variable, but is local to the before_close event, so
you will need to set cancel to true within the event code itself.

HTH,
Bernie
MS Excel MVP


"WillRn" wrote in message
...
I am in the process of creating an "exit menu" that triggers on the
"before_close" event on the workbook. The menu itself is fairly simple
offering 4 buttons:

1. Email spreadsheet
2. Save spreadsheet
3. Return to the worksheet
4. Exit the worksheet

The email, save, and exit buttons work fine. The trouble that I am having

is
the "Return to worksheet" button.

I have tried the following code:

Private Sub ReturnButton_Click()
Cancel = True
Unload ExitOptions
Application.ExecuteExcel4Macro "HALT(True)"
End Sub

If I try to cancel the exit, the sheet still closes. I can't seem to get

it
to return an halt the closing process.

I have tried quite a few permutations, but still nada,

Any suggestions?

WillRn



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Exit Menu Troubles

Okay, that makes sense. But how do I use my custom menu and stay in the
before_close event so that cancel=true will work?


"Bernie Deitrick" wrote:

Will,

Cancel is not a global variable, but is local to the before_close event, so
you will need to set cancel to true within the event code itself.

HTH,
Bernie
MS Excel MVP


"WillRn" wrote in message
...
I am in the process of creating an "exit menu" that triggers on the
"before_close" event on the workbook. The menu itself is fairly simple
offering 4 buttons:

1. Email spreadsheet
2. Save spreadsheet
3. Return to the worksheet
4. Exit the worksheet

The email, save, and exit buttons work fine. The trouble that I am having

is
the "Return to worksheet" button.

I have tried the following code:

Private Sub ReturnButton_Click()
Cancel = True
Unload ExitOptions
Application.ExecuteExcel4Macro "HALT(True)"
End Sub

If I try to cancel the exit, the sheet still closes. I can't seem to get

it
to return an halt the closing process.

I have tried quite a few permutations, but still nada,

Any suggestions?

WillRn




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Exit Menu Troubles

Will,

You could declare a public global variable that your button click sets to
true:

At the top of a module
Public glblCancel As Boolean

Then in your sub that show the userform:

Sub TryNow()
glblCancel = False ' initialize
Load UserForm1
UserForm1.Show
'user interacts with the userform
MsgBox glblCancel ' this is set in the click event
End Sub

Private Sub ReturnButton_Click()
glblCancel = True
Unload ExitOptions
Application.ExecuteExcel4Macro "HALT(True)"
End Sub

Then in the before close event:

....
Cancel = glblCancel
.....

HTH,
Bernie
MS Excel MVP


"WillRn" wrote in message
...
Okay, that makes sense. But how do I use my custom menu and stay in the
before_close event so that cancel=true will work?


"Bernie Deitrick" wrote:

Will,

Cancel is not a global variable, but is local to the before_close event,

so
you will need to set cancel to true within the event code itself.

HTH,
Bernie
MS Excel MVP


"WillRn" wrote in message
...
I am in the process of creating an "exit menu" that triggers on the
"before_close" event on the workbook. The menu itself is fairly simple
offering 4 buttons:

1. Email spreadsheet
2. Save spreadsheet
3. Return to the worksheet
4. Exit the worksheet

The email, save, and exit buttons work fine. The trouble that I am

having
is
the "Return to worksheet" button.

I have tried the following code:

Private Sub ReturnButton_Click()
Cancel = True
Unload ExitOptions
Application.ExecuteExcel4Macro "HALT(True)"
End Sub

If I try to cancel the exit, the sheet still closes. I can't seem to

get
it
to return an halt the closing process.

I have tried quite a few permutations, but still nada,

Any suggestions?

WillRn






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 50
Default Exit Menu Troubles

That worked,

Thanks a bunch!

"Bernie Deitrick" wrote:

Will,

You could declare a public global variable that your button click sets to
true:

At the top of a module
Public glblCancel As Boolean

Then in your sub that show the userform:

Sub TryNow()
glblCancel = False ' initialize
Load UserForm1
UserForm1.Show
'user interacts with the userform
MsgBox glblCancel ' this is set in the click event
End Sub

Private Sub ReturnButton_Click()
glblCancel = True
Unload ExitOptions
Application.ExecuteExcel4Macro "HALT(True)"
End Sub

Then in the before close event:

....
Cancel = glblCancel
.....

HTH,
Bernie
MS Excel MVP


"WillRn" wrote in message
...
Okay, that makes sense. But how do I use my custom menu and stay in the
before_close event so that cancel=true will work?


"Bernie Deitrick" wrote:

Will,

Cancel is not a global variable, but is local to the before_close event,

so
you will need to set cancel to true within the event code itself.

HTH,
Bernie
MS Excel MVP


"WillRn" wrote in message
...
I am in the process of creating an "exit menu" that triggers on the
"before_close" event on the workbook. The menu itself is fairly simple
offering 4 buttons:

1. Email spreadsheet
2. Save spreadsheet
3. Return to the worksheet
4. Exit the worksheet

The email, save, and exit buttons work fine. The trouble that I am

having
is
the "Return to worksheet" button.

I have tried the following code:

Private Sub ReturnButton_Click()
Cancel = True
Unload ExitOptions
Application.ExecuteExcel4Macro "HALT(True)"
End Sub

If I try to cancel the exit, the sheet still closes. I can't seem to

get
it
to return an halt the closing process.

I have tried quite a few permutations, but still nada,

Any suggestions?

WillRn






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
Troubles Jonas Krogh Excel Discussion (Misc queries) 1 October 22nd 09 11:14 AM
COM Add-in Troubles Howard Excel Discussion (Misc queries) 0 May 22nd 07 01:59 PM
IF troubles JG Excel Worksheet Functions 6 December 24th 06 04:58 AM
Can only exit the program from the file menu Chuck Bowser Excel Discussion (Misc queries) 1 April 11th 06 03:08 PM
If a called sub exit, how to the caller exit right away? luvgreen[_4_] Excel Programming 4 February 24th 04 05:06 PM


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