ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Case Select (https://www.excelbanter.com/excel-programming/384410-case-select.html)

Daviv

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!

John Coleman

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!




Daviv

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!






All times are GMT +1. The time now is 02:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com