Closing file with macro

D

dwake

I would like to automatically close a file without saving using a macro. Any
suggestions?
 
D

Dave Peterson

Dim wkbk as workbook

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

wkbk.close savechanges:=false
 
B

Bryan

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.
 
G

Gord Dibben

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
 
Top