One way to test if someone else already has an Excel file open is to use the FileLen function in VBA. This function returns the size of a file in bytes. If the file is open by another user, the FileLen function will return 0.
Here's an example of how you can use the FileLen function to check if an Excel file is open:
You can use this code in your VBA macro to check if the file is open before attempting to write to it. If the file is open, you can display a message to the user or take some other appropriate action.
Keep in mind that the FileLen function only works if the file is located on the local machine. If the file is located on a network drive or in a cloud storage service like OneDrive, the FileLen function will not work. In these cases, you may need to use a different method to check if the file is open, such as trying to open the file in read-only mode and handling any errors that occur.
Bookmarks