Excel autoclose file




















Name, Len ThisWorkbook. Name - i 'uninstall addin if it is installed If AddIns wbName. Installed Then AddIns wbName. I sometimes run into a "Running time Error" when open the workbook that has this code built into it. Anyway to write this code better for it to be more stable?

I noticed the same thing. And found the same solution The above code is not working when a cell is active. That is 1. In this case the code is not working. Protect Worksheet. If your VBA code isn't written correctly, it may end up shutting down whichever workbook has focus at the current time—clearly a result you don't want to occur.

Further, what do you do with unsaved changes when closing? If you save them, you run into the issue that perhaps the user didn't intend to save them. If you don't save them, the converse problem occurs—perhaps there was a lot of data that needed to be saved.

You can't have the closing procedure ask if information should be saved; that would keep the workbook tied up as surely as keeping it open and unused would. A possible solution is to simply share or co-author Excel and Excel in Office the workbook. If you enable sharing or co-authoring as discussed in other ExcelTips , then multiple people can have the same workbook open at the same time.

If one of those people leaves it open, then nobody else is inconvenienced because they can still open it and, optionally, make changes in the workbook. If you decide to go the macro-based route, then the solution is rather simple. You need some sort of timer structure easily implemented through use of the OnTime method and some way to check to see if someone is doing something in the workbook. To start, add the following code to a standard macro module. Note that there are three routines to be added:.

These three routines are fairly straightforward. The first two respectively turn on the timer and turn it off. Note that these routines utilize the DownTime variable, which is declared outside of any of the routines.

In this way its contents can be utilized in multiple routines. The third routine, ShutDown, is the one that actually closes the workbook. It is only invoked if the OnTime method expires, at the end of an hour. It closes the workbook without saving any changes that may have been made.

The next routines there are four of them need to be added to the ThisWorkbook object. In the code window that Excel opens, place these routines:. The first two routines are triggered when the workbook is opened and when it is closed; they start the timer and turn it off. The other two routines are executed automatically whenever a worksheet is recalculated or whenever someone makes a selection in the workbook.

Both are good indicators that someone is using the workbook it is not inactively open. They stop the timer and then restart it, so that the one-hour countdown starts over. There is a downside to using a set of macros such as these: you effectively eliminate Excel's Undo capability. Sometimes, this is caused due to Word not being able to access the default printer. If this is the problem, then you will need to update your printer driver for default printer.

See if you have any of them installed. Close them one by one and see whether it helps. Login to Windows with a new user profile and see if problem is resolved. How satisfied are you with this reply? Thanks for your feedback, it helps us improve the site. Ugo Lopez Independent Advisor. If you have recently installed any software then check the following:. Excel file that gets opened from a potentially unsafe location like the internet, email attachments, downloaded from any third party source, etc.

This feature of Excel Protected-View restricts the user to make any modification in their opened Excel spreadsheet. So, you can turn off the Protected-View security warning messages in Excel to resolve Excel open and close immediately like problems. So, when you start your Excel application it will automatically run itself. For stopping the automatic running of macros you need to just hold on to the SHIFT option at the time of starting your Excel application.

I have provided several promising ways to fix Excel file closes immediately after opening issue. All the above-listed fixes are easy to apply and implement. If none of the listed manual methods work to fix Excel automatically closes when opening file problem then go the reliable solution like Excel repair tool.

If you have any questions related to the article, then freely ask it on our Repair MS Excel Facebook and Twitter page.



0コメント

  • 1000 / 1000