Question as per title. I realise/accept that this could be dangerous in certain situations (e.g. if workbook file currently in use)
Question as per title. I realise/accept that this could be dangerous in certain situations (e.g. if workbook file currently in use)
*******************************************************
HELP WANTED! (Links to Forum threads)
Trying to create reusable code for Custom Events at Workbook (not Application) level
*******************************************************
Try this code
![]()
Please Login or Register to view this content.
If you think someone helped you, click on the "* Add Reputation" as a way to say thank you.
If your problem is solved, go to Thread Tools and select Mark This Thread Solved
TY saravnepali
I tried the code.
- It closes the workbook if it is open in the same instance of Excel that the VBA is running in.
- It doesn't close the workbook if the workbook is open in a different instance of Excel.
Hi,
See the file associated with post #2 in the following thread (API references coded for 32 bit Excel only): http://www.excelforum.com/excel-prog...instances.html
The file contains the Macro DisplayDataForAllOpenExcelInstances() below that displays data about each open Excel File in all instances of Excel which should help you get started. There is also a Macro in the file that closes all open Excel Files in All Instances of Excel, except the file that is running the code. Please NOTE that Macro DisplayDataForAllOpenExcelInstances() overwrites the contents of Sheet 'Main' in the 'Active Workbook'. A runtime error will occur if Sheet 'Main' DOES NOT EXIST.
Lewis![]()
Please Login or Register to view this content.
Thanks Lewis. I will see if I can get time to test this later this month. Will let you know how it goes.
1. In total, the topic is not entirely clear, because it is not known whether it is an open file on the local computer, or whether it is an open file from e.g. a company network. Depending on where you open the file, different ways to handle these situations will apply
2. "Open ...For Input ..."
This method is not credible (reliable ?), see 'Open' statement description in Microsoft context help:
"Important - In Binary, Input, and Random modes, you can open a file using a different file number without first closing the file. In Append and Output modes, you must close a file before opening it with a different file number",
so using 'Input' for 'Open' statement you can open an already open file and declare (state, tell) that it has not been opened before.
3. A brief "web query" shows interesting solutions that can be customized to this topic.
A. Solution of Peter Thornton - lists all Excel instances nicely:
https://social.msdn.microsoft.com/Fo...forum=exceldev
B. "Check Whether an Excel File Is Open on a Network"
http://www.java2s.com/Code/VBA-Excel...onaNetwork.htm
and in many, many places ...
... on the forum something would also be found, but I admit that I was not looking here ...![]()
Thanks for the suggestion Lewis. The 4th goal is now resolved by using GetObject on the open workbook followed by closing the object.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks