Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming,microsoft.public.vb.general.discussion
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.vb.general.discussion,microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.vb.general.discussion,microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.vb.general.discussion,microsoft.public.excel.programming
|
|||
|
|||
![]()
'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
![]()
Posted to microsoft.public.vb.general.discussion,microsoft.public.excel.programming
|
|||
|
|||
![]()
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
![]()
Posted to microsoft.public.vb.general.discussion,microsoft.public.excel.programming
|
|||
|
|||
![]()
"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
![]()
Posted to microsoft.public.vb.general.discussion,microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do you force excel to save on close | Excel Discussion (Misc queries) | |||
Is there a way to force Excel to close workbooks independently? | Excel Discussion (Misc queries) | |||
How Close Excel from CMD prompt? | Excel Programming | |||
Macro to force Excel to close after a given timeframe of inactivit | Excel Programming | |||
Excel close/save/prompt problem | Excel Programming |