#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Case Select

I have the following code:


InitFileName = Range("File").Value & Range("Project").Value & " " & "Insp._
Report," & " " & Format(Report(0, 1), "d-mmm-yy") & ".xls"
MsgResult = MsgBox("Have you saved the file?", vbYesNoCancel)
Select Case MsgResult
Case vbNo
FName = Application.GetSaveAsFilename(InitFileName,
"Excel File_(*.xls),*.xls")
ActiveWorkbook.SaveAs FName, CreateBackup = False
Cancel = True
Exit Sub
Case vbYes
ThisWorkbook.Saved = True
Application.Quit
Case vbCancel
Exit Sub
End Select
End Sub

When I select "cancel", the application quit instead of just exiting the sub
and going back to the worksheet.

Thanks!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 274
Default Case Select

Is this in Workbook_BeforeClose ? If so, try

Case vbCancel
Cancel = True
Exit Sub

Hope that helps

-John Coleman


On Mar 2, 6:32 pm, Daviv wrote:
I have the following code:

InitFileName = Range("File").Value & Range("Project").Value & " " & "Insp._
Report," & " " & Format(Report(0, 1), "d-mmm-yy") & ".xls"
MsgResult = MsgBox("Have you saved the file?", vbYesNoCancel)
Select Case MsgResult
Case vbNo
FName = Application.GetSaveAsFilename(InitFileName,
"Excel File_(*.xls),*.xls")
ActiveWorkbook.SaveAs FName, CreateBackup = False
Cancel = True
Exit Sub
Case vbYes
ThisWorkbook.Saved = True
Application.Quit
Case vbCancel
Exit Sub
End Select
End Sub

When I select "cancel", the application quit instead of just exiting the sub
and going back to the worksheet.

Thanks!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Case Select

Thanks a million!
--
Thanks!


"John Coleman" wrote:

Is this in Workbook_BeforeClose ? If so, try

Case vbCancel
Cancel = True
Exit Sub

Hope that helps

-John Coleman


On Mar 2, 6:32 pm, Daviv wrote:
I have the following code:

InitFileName = Range("File").Value & Range("Project").Value & " " & "Insp._
Report," & " " & Format(Report(0, 1), "d-mmm-yy") & ".xls"
MsgResult = MsgBox("Have you saved the file?", vbYesNoCancel)
Select Case MsgResult
Case vbNo
FName = Application.GetSaveAsFilename(InitFileName,
"Excel File_(*.xls),*.xls")
ActiveWorkbook.SaveAs FName, CreateBackup = False
Cancel = True
Exit Sub
Case vbYes
ThisWorkbook.Saved = True
Application.Quit
Case vbCancel
Exit Sub
End Select
End Sub

When I select "cancel", the application quit instead of just exiting the sub
and going back to the worksheet.

Thanks!




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
Case without Select Case error problem Ayo Excel Discussion (Misc queries) 2 May 16th 08 03:48 PM
End Select without Select Case, Block If without End If errors Atreides Excel Programming 12 November 17th 06 05:10 PM
For Each with Select Case helmekki[_31_] Excel Programming 0 October 15th 04 03:49 AM
For Each with Select Case helmekki[_30_] Excel Programming 0 October 15th 04 03:36 AM


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