Reverse the close command
MZ Tools makes life easier for the Excel VBA coder
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 4 of 4

Thread: Reverse the close command

  1. #1
    New Member
    Join Date
    Mar 2002
    Posts
    22
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    Any idea how to stop a file from closing when a before close event has been met. here is what I have so far:

    Private Sub Workbook_BeforeClose(Cancel As Boolean)

    If ActiveSheet.Cells(85, 12).Value > 0 And ActiveSheet.Cells(85, 9).Value < 1 Then

    MsgBox "Enter a Travel Order Number"
    Else: Close
    End If

    End Sub

    After the MsgBox has been clicked I want the file not to close and return to the worksheet.

    Any help would be apreciated.

    Dale

  2. #2
    MrExcel MVP Mark O'Brien's Avatar
    Join Date
    Feb 2002
    Location
    Columbus, OH, USA
    Posts
    3,530
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    After your message box line sitck in:


    Cancel = True


  3. #3
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    Any idea how to stop a file from closing when a before close event has been met. here is what I have so far:

    Private Sub Workbook_BeforeClose(Cancel As Boolean)

    If ActiveSheet.Cells(85, 12).Value > 0 And ActiveSheet.Cells(85, 9).Value < 1 Then

    MsgBox "Enter a Travel Order Number"
    cancel = true '<<<<#########################
    Else: Close
    End If

    End Sub

    After the MsgBox has been clicked I want the file not to close and return to the worksheet.

    Any help would be apreciated.

    Dale

  4. #4
    Rest in Peace
    Join Date
    Feb 2002
    Posts
    1,582
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi Dale

    The Cancel argument should do it.


    Private Sub Workbook_BeforeClose(Cancel As Boolean)

    If ActiveSheet.Cells(85, 12).Value > 0 And ActiveSheet.Cells(85, 9).Value < 1 Then

    MsgBox "Enter a Travel Order Number"
    Cancel = True
    End If

    End Sub

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

 

 
DMCA.com