Closing file with macro

  • Thread starter Thread starter dwake
  • Start date Start date
D

dwake

I would like to automatically close a file without saving using a macro. Any
suggestions?
 
Dim wkbk as workbook

Set wkbk = workbooks("someworkbooknameherethat'salreadyopen.xls")

wkbk.close savechanges:=false
 
You can record a macro that will copy all of the movements. To record the
macro, go to Tools ==> Macro ==> Record Macro. That will pull up the Record
Macro window, name your macro, and give it a shortcut key if you want. Once
you hit ok, all of your movements will be recorded until you hit the stop
macro button. All you need to do is close the file without saving and stop
the macro.
 
Might be a good idea to record the macro in some other workbook than the one
you're closing without saving<g>

When you record to new workbook all you get from the recorder is

Sub Macro3()
ActiveWorkbook.Close
End Sub

Which closes the original workbook with a "do you want to save" message.

So you would have to add the bits that Dave posted.


Gord Dibben MS Excel MVP
 
Back
Top