How to close a spreadshee without Excel message

accessfever

Registered User.
Local time
Yesterday, 22:40
Joined
Feb 7, 2010
Messages
101
I have a macro to export an Access table to a text file. Then I use an Excel macro to open the text file and copy/paste to an Excel template. In the Excel macro, I write a code below to close the text file:

Activeworkbook.close

The Excel prompts a standard massage with 3 buttons: save, notsave and cancel. Everytime, I click the notsave button to close the text file.

Is there a way to write some codes to bypass this standard message? What I want is to close down the text file without any change.

any idea?
 
Hi - mabye,

Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
ActiveWorkbook.Close False
End Sub


If you would like to save the changes to the Excel workbook, change the False to True in Activeworkbook.close
 
hi,

Sorry I should mention that the close action is in my existing codes which includes a bunch of other actions as well.

i am still new to VBA code. I think your code would work. However, how I revise your code to include in my existing code? I tried to copy & paste your code in my existing code and executed it but a fatal message returns like this: Compile error - Expected End Sub.

Please help!!!
 
No worries - this can be easily solved. In your code, where you have the line,

Code:
activeworkbook.close

Replace it with;

Code:
activeworkbook.close False

The "false" is the arguement that indicates you don't want to save changes - just make sure that the workbook you want to close w/out saving is actually the active workbook. Post back if this doesn't work for you.
 

Users who are viewing this thread

Back
Top Bottom