Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.vb.general.discussion
external usenet poster
 
Posts: 97
Default How to force close the worksheet without having Excel prompt?

How to force close the worksheet without having Excel prompt?

Right now I use this:
moExcel2ndTask.Workbooks.Close
and the Excel prompt is:
"
Do you want to save changes to ...xls?
Microsoft Office Excel recalculates formulas when opening files saved by an
earlier version of Excel.
"
Thanks,
Jack


  #2   Report Post  
Posted to microsoft.public.vb.general.discussion,microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default How to force close the worksheet without having Excel prompt?

From
moExcel2ndTask.Workbooks.Close

to
moExcel2ndTask.Workbooks.Close savechanges = true

or
moExcel2ndTask.Workbooks.Close savechanges = false

"Jack" wrote:

How to force close the worksheet without having Excel prompt?

Right now I use this:
moExcel2ndTask.Workbooks.Close
and the Excel prompt is:
"
Do you want to save changes to ...xls?
Microsoft Office Excel recalculates formulas when opening files saved by an
earlier version of Excel.
"
Thanks,
Jack



  #3   Report Post  
Posted to microsoft.public.vb.general.discussion,microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default How to force close the worksheet without having Excel prompt?

I am using visual basic.
When I do:
moExcel2ndTask.Workbooks.Close savechanges = False
I have vbasic compile error:
"Wrong number of arguments or invalid property assignment"
Thanks,
Jack

"Joel" wrote in message
...
From
moExcel2ndTask.Workbooks.Close

to
moExcel2ndTask.Workbooks.Close savechanges = true

or
moExcel2ndTask.Workbooks.Close savechanges = false

"Jack" wrote:

How to force close the worksheet without having Excel prompt?

Right now I use this:
moExcel2ndTask.Workbooks.Close
and the Excel prompt is:
"
Do you want to save changes to ...xls?
Microsoft Office Excel recalculates formulas when opening files saved by
an
earlier version of Excel.
"
Thanks,
Jack





  #4   Report Post  
Posted to microsoft.public.vb.general.discussion,microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default How to force close the worksheet without having Excel prompt?

'Close' with the Workbooks collection should not have any arguments

To avoid that message could do

For Each wb in moExcel2ndTask.Workbooks
'' maybe
' If wb.Saved = False then ' ?
wb.Close False
next

or

moExcel2ndTask.Displayalerts = False
moExcel2ndTask.Workbooks.Close
moExcel2ndTask.Displayalerts = True


As in the example above, Close with a single workbook can have optional
arguments, however if naming an argument like this
.... savechanges = true

it needs a colon
Savechanges:= true

Regards,
Peter T



"Joel" wrote in message
...
From
moExcel2ndTask.Workbooks.Close

to
moExcel2ndTask.Workbooks.Close savechanges = true

or
moExcel2ndTask.Workbooks.Close savechanges = false

"Jack" wrote:

How to force close the worksheet without having Excel prompt?

Right now I use this:
moExcel2ndTask.Workbooks.Close
and the Excel prompt is:
"
Do you want to save changes to ...xls?
Microsoft Office Excel recalculates formulas when opening files saved by

an
earlier version of Excel.
"
Thanks,
Jack





  #5   Report Post  
Posted to microsoft.public.vb.general.discussion,microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default How to force close the worksheet without having Excel prompt?

Thank you Peter.
I've found out that:
moExcelApp.ActiveWorkbook.Close SaveChanges:=False
does work.
But I think I prefer your solution (again :) )
moExcel2ndTask.Displayalerts = False
moExcel2ndTask.Workbooks.Close

I do not need this:
moExcel2ndTask.Displayalerts = True


because that code is executed when my app disconnects from Excel.
I am still confused about all these workbooks in Excel.
I am afraid for example that doing:
moExcel2ndTask.ActiveWorkbook.Close SaveChanges:=False
may not close all the books, or will it do it?

moExcel2ndTask is created by my app only
Set moExcel2ndTask = CreateObject("Excel.Application")
moExcel2ndTask.Workbooks.Open (moExcelApp.ActiveWorkbook.FullName)

in difference to:
moExcelApp
which may be created (and opened) by my app or it could be already opened by
the user before my app starts.

Which invites another question:
Should my code close the workbook if it was not opened by my app?
Thanks,
Jack



"Peter T" <peter_t@discussions wrote in message
...
'Close' with the Workbooks collection should not have any arguments

To avoid that message could do

For Each wb in moExcel2ndTask.Workbooks
'' maybe
' If wb.Saved = False then ' ?
wb.Close False
next

or

moExcel2ndTask.Displayalerts = False
moExcel2ndTask.Workbooks.Close
moExcel2ndTask.Displayalerts = True


As in the example above, Close with a single workbook can have optional
arguments, however if naming an argument like this
.... savechanges = true

it needs a colon
Savechanges:= true

Regards,
Peter T



"Joel" wrote in message
...
From
moExcel2ndTask.Workbooks.Close

to
moExcel2ndTask.Workbooks.Close savechanges = true

or
moExcel2ndTask.Workbooks.Close savechanges = false

"Jack" wrote:

How to force close the worksheet without having Excel prompt?

Right now I use this:
moExcel2ndTask.Workbooks.Close
and the Excel prompt is:
"
Do you want to save changes to ...xls?
Microsoft Office Excel recalculates formulas when opening files saved
by

an
earlier version of Excel.
"
Thanks,
Jack









  #6   Report Post  
Posted to microsoft.public.vb.general.discussion,microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default How to force close the worksheet without having Excel prompt?

"Jack" wrote in message
Thank you Peter.
I've found out that:
moExcelApp.ActiveWorkbook.Close SaveChanges:=False
does work.
But I think I prefer your solution (again :) )
moExcel2ndTask.Displayalerts = False
moExcel2ndTask.Workbooks.Close


It's not a matter of preference. The examples I posted will close ALL
workbooks without saving, which is what you asked for.

..ActiveWorkbook.Close
merely closes the "activeworkbook", but no others

As yours is an automated instance which you maintain as invisible, and the
user won't touch it(?), you can be pretty confident if you only opened or
created one workbook you only need to close the single activeworkbook.

I do not need this:
moExcel2ndTask.Displayalerts = True


because that code is executed when my app disconnects from Excel.


OK, if you are sure you won't need any other unexpected yet possibly useful
messages.

I am still confused about all these workbooks in Excel.
I am afraid for example that doing:
moExcel2ndTask.ActiveWorkbook.Close SaveChanges:=False
may not close all the books, or will it do it?


No it won't as explained above. But surely you will know how many workbooks
exist in your instance. When you create an automated instance no workbooks
which normally load on start-up will load, such as Addins, Personal, or the
default empty workbook. If you know there is only one non-hidden workbook
"it will do it". But if you have opened others or are in doubt use either of
the close-all approaches as previously posted.


moExcel2ndTask is created by my app only
Set moExcel2ndTask = CreateObject("Excel.Application")
moExcel2ndTask.Workbooks.Open (moExcelApp.ActiveWorkbook.FullName)

in difference to:
moExcelApp
which may be created (and opened) by my app or it could be already opened

by
the user before my app starts.

Which invites another question:
Should my code close the workbook if it was not opened by my app?


I'm confused. I thought you said the workbook was opened by you in your
automated instance (invisible to user). If so it's entirely up to you when
you close it with or without saving changes (though if it's a ReadOnly copy
of a workbook already open in another instance you wouldn't be able to save
it anyway).

Normally you should not close a workbook that was opened by a user, unless
there is some very good reason in a particular enviroment or scenario.

Thanks,
Jack


Regards,
Peter T




"Peter T" <peter_t@discussions wrote in message
...
'Close' with the Workbooks collection should not have any arguments

To avoid that message could do

For Each wb in moExcel2ndTask.Workbooks
'' maybe
' If wb.Saved = False then ' ?
wb.Close False
next

or

moExcel2ndTask.Displayalerts = False
moExcel2ndTask.Workbooks.Close
moExcel2ndTask.Displayalerts = True


As in the example above, Close with a single workbook can have optional
arguments, however if naming an argument like this
.... savechanges = true

it needs a colon
Savechanges:= true

Regards,
Peter T



"Joel" wrote in message
...
From
moExcel2ndTask.Workbooks.Close

to
moExcel2ndTask.Workbooks.Close savechanges = true

or
moExcel2ndTask.Workbooks.Close savechanges = false

"Jack" wrote:

How to force close the worksheet without having Excel prompt?

Right now I use this:
moExcel2ndTask.Workbooks.Close
and the Excel prompt is:
"
Do you want to save changes to ...xls?
Microsoft Office Excel recalculates formulas when opening files saved
by

an
earlier version of Excel.
"
Thanks,
Jack









  #7   Report Post  
Posted to microsoft.public.vb.general.discussion,microsoft.public.excel.programming
external usenet poster
 
Posts: 97
Default How to force close the worksheet without having Excel prompt?

Peter, thank you for being with me.
As you can see these:
Set moExcel2ndTask = CreateObject("Excel.Application")
moExcel2ndTask.Workbooks.Open (moExcelApp.ActiveWorkbook.FullName)

moExcel2ndTask is created by my app but it is an invisible copy of:
1.
previously opened workbook by the user
or
2.
any active workbook previously opened by the user (if not specific wkb is
specified in app preferences)
3.
or
the specific (set in app preferences) workbook which if is not already
opened (see 1 above) will be opened on startup by my app.

So, as you can see I have to deal with several screnarios in here.
Jack


"Peter T" <peter_t@discussions wrote in message
...
"Jack" wrote in message
Thank you Peter.
I've found out that:
moExcelApp.ActiveWorkbook.Close SaveChanges:=False
does work.
But I think I prefer your solution (again :) )
moExcel2ndTask.Displayalerts = False
moExcel2ndTask.Workbooks.Close


It's not a matter of preference. The examples I posted will close ALL
workbooks without saving, which is what you asked for.

.ActiveWorkbook.Close
merely closes the "activeworkbook", but no others

As yours is an automated instance which you maintain as invisible, and the
user won't touch it(?), you can be pretty confident if you only opened or
created one workbook you only need to close the single activeworkbook.

I do not need this:
moExcel2ndTask.Displayalerts = True


because that code is executed when my app disconnects from Excel.


OK, if you are sure you won't need any other unexpected yet possibly
useful
messages.

I am still confused about all these workbooks in Excel.
I am afraid for example that doing:
moExcel2ndTask.ActiveWorkbook.Close SaveChanges:=False
may not close all the books, or will it do it?


No it won't as explained above. But surely you will know how many
workbooks
exist in your instance. When you create an automated instance no workbooks
which normally load on start-up will load, such as Addins, Personal, or
the
default empty workbook. If you know there is only one non-hidden workbook
"it will do it". But if you have opened others or are in doubt use either
of
the close-all approaches as previously posted.


moExcel2ndTask is created by my app only
Set moExcel2ndTask = CreateObject("Excel.Application")
moExcel2ndTask.Workbooks.Open
(moExcelApp.ActiveWorkbook.FullName)

in difference to:
moExcelApp
which may be created (and opened) by my app or it could be already opened

by
the user before my app starts.

Which invites another question:
Should my code close the workbook if it was not opened by my app?


I'm confused. I thought you said the workbook was opened by you in your
automated instance (invisible to user). If so it's entirely up to you when
you close it with or without saving changes (though if it's a ReadOnly
copy
of a workbook already open in another instance you wouldn't be able to
save
it anyway).

Normally you should not close a workbook that was opened by a user, unless
there is some very good reason in a particular enviroment or scenario.

Thanks,
Jack


Regards,
Peter T




"Peter T" <peter_t@discussions wrote in message
...
'Close' with the Workbooks collection should not have any arguments

To avoid that message could do

For Each wb in moExcel2ndTask.Workbooks
'' maybe
' If wb.Saved = False then ' ?
wb.Close False
next

or

moExcel2ndTask.Displayalerts = False
moExcel2ndTask.Workbooks.Close
moExcel2ndTask.Displayalerts = True


As in the example above, Close with a single workbook can have optional
arguments, however if naming an argument like this
.... savechanges = true
it needs a colon
Savechanges:= true

Regards,
Peter T



"Joel" wrote in message
...
From
moExcel2ndTask.Workbooks.Close

to
moExcel2ndTask.Workbooks.Close savechanges = true

or
moExcel2ndTask.Workbooks.Close savechanges = false

"Jack" wrote:

How to force close the worksheet without having Excel prompt?

Right now I use this:
moExcel2ndTask.Workbooks.Close
and the Excel prompt is:
"
Do you want to save changes to ...xls?
Microsoft Office Excel recalculates formulas when opening files
saved
by
an
earlier version of Excel.
"
Thanks,
Jack











Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do you force excel to save on close Tom Hewitt Excel Discussion (Misc queries) 3 September 21st 06 10:55 AM
Is there a way to force Excel to close workbooks independently? Cam Excel Discussion (Misc queries) 4 February 2nd 06 07:43 PM
How Close Excel from CMD prompt? Al Franz Excel Programming 5 August 20th 05 09:14 PM
Macro to force Excel to close after a given timeframe of inactivit bobm Excel Programming 2 August 12th 05 02:41 AM
Excel close/save/prompt problem clayton[_2_] Excel Programming 4 January 21st 04 11:45 PM


All times are GMT +1. The time now is 03:46 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"