If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Workbook_Close() problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-07-05, 15:44
bhavesh78 bhavesh78 is offline
Registered User
 
Join Date: Dec 2004
Posts: 78
Question Workbook_Close() problem

I am using Private Sub Workbook_Close() to execute some code before the workbook is closed. Even though the user says Cancel when the Save box appers the above code runs. How can this be prevented. I tried using Workbook_DeActivate() but it doesnt work.

~BS
Reply With Quote
  #2 (permalink)  
Old 01-07-05, 17:04
shades shades is offline
Registered User
 
Join Date: Oct 2003
Posts: 1,091
Can you post your entire code? (Sanitize if necessary)
__________________
old, slow, and confused
but at least I'm inconsistent!

Rich
(retired Excel 2003 user, 3/28/2008)

How to ask a question on forums
Reply With Quote
  #3 (permalink)  
Old 01-07-05, 20:47
bhavesh78 bhavesh78 is offline
Registered User
 
Join Date: Dec 2004
Posts: 78
Question

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean) 
    Dim WBkName As String
    WBkName = Right(ActiveWorkbook.Name, 3) 
    If WBkName <> "xnv" Then     'or WBkName = "xls"
        Call EnableCopyCutAndPaste
    End If
End Sub
This code checks if the file extension in xls or xnv (these extensions generated by excel addin softwares) and calls EnableCopyCutAndPaste only if file extension is not xnv.

Copy/Cut is disabled in xls file on worksheet_open. It is only enabled after xls file is closed, hence the above code.

The problem is that if I select file-->close and then cancel button on the xls file, xls file remains open and the code for Workbook_BeforeClose is also executed thus enabling copy/paste.

~BS.
Reply With Quote
  #4 (permalink)  
Old 01-08-05, 03:34
savbill savbill is offline
Registered User
 
Join Date: Feb 2004
Posts: 533
I have used a variation from an example at 'The Spread Sheet Page', j-walk.com.

See the example about the middle of the page at this link.
Handling the Workbook BeforeClose Event



/
__________________
~

Bill
Reply With Quote
  #5 (permalink)  
Old 01-10-05, 13:21
bhavesh78 bhavesh78 is offline
Registered User
 
Join Date: Dec 2004
Posts: 78
Thumbs up

Thanks Bill. This is what I needed. Just added Me.Close in VbYes and VbNo so that worksheet is closed. Also if Me.Close is not entered, excel prompts its own Save box again.

Thanks again.

~BS
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On