PC Review


Reply
Thread Tools Rate Thread

auto close in Excel 2007

 
 
jim
Guest
Posts: n/a
 
      26th Nov 2008
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
 
Reply With Quote
 
 
 
 
Patrick Molloy
Guest
Posts: n/a
 
      26th Nov 2008
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




"jim" wrote:

> 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

 
Reply With Quote
 
jim
Guest
Posts: n/a
 
      26th Nov 2008
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.

"Patrick Molloy" wrote:

> 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
>
>
>
>
> "jim" wrote:
>
> > 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

 
Reply With Quote
 
jim
Guest
Posts: n/a
 
      26th Nov 2008
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

"jim" wrote:

> 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.
>
> "Patrick Molloy" wrote:
>
> > 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
> >
> >
> >
> >
> > "jim" wrote:
> >
> > > 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

 
Reply With Quote
 
Michelle
Guest
Posts: n/a
 
      9th Oct 2009
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


On Wed, 26 Nov 2008 09:43:01 -0800, jim wrote:

> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Close the Auto-active IME in Word 2007 Beta? =?Utf-8?B?cENoYW8=?= Microsoft Word Document Management 3 13th Jun 2006 02:53 AM
How to Close the Auto-active IME in Word 2007 Beta? =?Utf-8?B?cENoYW8=?= Microsoft Word Document Management 0 12th Jun 2006 01:37 PM
Auto Excel workbook close: save= false during an auto subroutine =?Utf-8?B?dG9td2FzaGVyZTI=?= Microsoft Excel Programming 10 16th Jun 2005 06:23 AM
Auto Close Excel Workbook MBlake Microsoft Excel Programming 2 2nd Jun 2005 09:44 PM
Auto close excel without saving John Haywood Microsoft Excel Programming 0 23rd Aug 2004 09:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:02 PM.