Make file drop dead on close

G

Guest

Using Windows 2003 and Office XP;

I have the following in ThisWorkbook:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Cancel = True
Application.EnableEvents = False
Application.DisplayAlerts = False
ThisWorkbook.Close SaveChanges:=False
Application.DisplayAlerts = True
Application.EnableEvents = True
End Sub

I know that the alerts and the events are not likely switched back on since
they come after the close; however, this file is set to open "Read Only" by
default (file attribute) and I cannot get this thing to close without a "Do
you want to save" message. I want the file to drop dead on close: i.e. no
warnings, no questions asked, no save.

How can I get this to work?
Thanks much in advance for your assistance.
 
M

Mark Lincoln

Put this in the This Workbook module:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

ThisWorkbook.Saved = True

End Sub

That should do it.

Mark Lincoln
 
G

Guest

Hi Mark,

Sorry, but this doesn't work...

Now my file also runs hidden, so I don't know if that is a new wrinkle or
not. This did work for another file, that my problem file opened, but not the
main problem file that runs hidden.

Any other ideas?
 
G

Guest

Hello again,

Now it seems to be working; I'm not sure why it didn't at first...maybe it
just need to burn in or something...

Anyway thanks!

If anyone else has anything to add on this issue, I welcome your comments...
 
G

Guest

Hello again,

I was wrong! This method only works if the file property is set to not read
only!

Once set to open read only, it fails and still prompts me about saving...
any other ideas?
 
M

Mark Lincoln

The code works for me on a read-only file. Did you put the code in
the ThisWorkbook module in the read-only file? And did you remove the
read-only restriction before entering the code, then reset the file to
read-only?

Mark Lincoln
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Save BeforeClose 1
Can't delete sheets 8
Apparently not possible? 8
Excel close/save/prompt problem 4
Excel remaining open on workbook exit 3
Public Variable problem 19
Prevent code running 3
Disable Alert 5

Top