View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
Mike Mike is offline
external usenet poster
 
Posts: 3,101
Default close excel without saving

Tom,
Many many thanks, your code does work.
However an unforeseen problem has arisen.
I have a 'save as' macro that has been disabled by your code.
What I am trying to achieve is for nobody to alter my master workbook so
when it is closed it returns to it's pristine state, but also allowing the
user to save the work he has done as a different file name.
Any ideas ?
Thanks for all your trouble.
Mike

"Tom Ogilvy" wrote:

Since I copied it out of a workbook, it is right. Perhaps you didn't
correct for wordwrap.

here is one adjusted so you shouldn't have a wordwrap problem

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Saved = True
End Sub

Private Sub Workbook_BeforeSave( _
ByVal SaveAsUI As Boolean, _
Cancel As Boolean)
Cancel = True
End Sub

--
Regards,
Tom Ogilvy



"Mike" wrote in message
...
Tom,
Me again.
Have copied/pasted your code in but the second private sub is showing in

red
which indicates something is quite right.
Mike

"Tom Ogilvy" wrote:

in the ThisWorkbook module

Private Sub Workbook_BeforeClose(Cancel As Boolean)
ThisWorkbook.Saved = True
End Sub
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As
Boolean)
cancel = True
End Sub

After you add the code, you will have to disable macros manually, then

save
the workbook.
--
Regards,
Tom Ogilvy


"Mike" wrote in message
...
I have inserted various code(s) in vbs "this workbook" using private

sub
auto_close
and private sub work_book close() after other code to close

excel/workbook
without saving or displaying a prompt but none seems to work.
I have used 'application.displayalerts = false'.' application.quit',
'thisworkbook.close savechanges:=false' etc etc in a variety of

different
combinations.
Perhaps I am placing the code in the wrong place or perhaps I should

be
saving before quitting or ..... ?
Can anyone help ?
Mike