auto close in Excel 2007

J

jim

I have the following code to auto close the workbook, but it does not work.
Any suggestions? Thanks for any assistance.

Sub Auto_Close()
'
' Auto_Close Macro
'
With ActiveWorkbook
.RunAutoMacros xlAutoClose
.Close
End With

'
End Sub
 
P

Patrick Molloy

AUTO_CLOSE is designe dto run when you try to close the workbook...similarly
AUTO_OPEN only runs when you open a workbook


yuo need some other event, eg using the ONTIME method


SUB StartShutdown()
Application.ONTIME TimeValue("17:00:00") , "shutdown"
END SUB
SUB shutdown()
thisworkbook.SAVED=TRUE
Thisworkbook.close false
application.exit
END SUB
 
J

jim

After thinking about it, that would make sense. Would there be any other
manner to close a workbook automatically, other than using the ONTIME
function? This workbook organizes data so the data can be exported to another
application, so what I'm trying to accomplish is having Excel do its majic
and close, whereby no operator has to open it, run the necessary macros and
then close it.
 
J

jim

Patrick, I used your suggestion but it still does not close. The language
follows:
Sub Auto_Open()
'
' M_Import_Telefile Macro
'
'
Workbooks.OpenText Filename:="I:\telefile_import.txt", Origin _
:=437, StartRow:=1, DataType:=xlDelimited,
TextQualifier:=xlDoubleQuote _
, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False,
Comma:=True _
, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), Array(2,
1), _
Array(3, 1)), TrailingMinusNumbers:=True
ActiveWindow.Close
End Sub

Sub StartShutdown()
Application.OnTime TimeValue("00:00:02"), "shutdown"
End Sub
Sub shutdown()
ThisWorkbook.Saved = True
ThisWorkbook.Close = False
Application.exit
End Sub
 
M

Michelle

You could try...

sub CloseMe
with thisworkbook
.saved = true ' use this to discard any changes
.save ' use this to save any changes without prompting
'and use neither if you want to be prompted in the normal way
.close
end with
end sub

change thisworkbook to activeworkbook if you want it close whichever is
active at the time, and don't forget to save the book as a macro-enabled
workbook - but you knew that

M
 

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

Top