Connecting Tech Pros Worldwide Forums | Help | Site Map

how to check if an excel spredsheet on a network share is already open by anther user

Newbie
 
Join Date: Feb 2009
Posts: 1
#1: Feb 9 '09
Hi,

Not sure if I am in the right section. Just have a query about manipulating excel spreadsheet using vbscript.

I am developing a vbscript which runs on client xp machines to retrieve certain user environment variables and to write the same as a record on an excel spreadsheet placed on a network share where the user has got write access to. However, due to the massive number of users in the domain it is expected that the same excel spreadsheet is likely to be used simultaneously by more than one user during which time my script fails and the user encounters an unexpected 'save/save as' excel dialog which he/she was not expecting in the first place(the script is expected to run without the knowledge of the user who has logged on). This is caused due to the fact that the xls file is already opened by the script running on another user's machine.

So I am trying to come up with a piece of code where it waits in an infinite loop (i.e. Do{ ......wait in the loop ...... While(XLS is locked) ....continue.......) until the lock on the xls is released and then continues with the rest of the script operation. Is there any way to check this using vbscript?

Please note I have come across scripts that can do a lot of things when the spredsheet in question is present locally on the machine where a lot of things can be done but I haven't come across an example for the above scenario.

Any help/suggestions will be highly appreciated. Thanks in advance!

jhardman's Avatar
Moderator
 
Join Date: Jan 2007
Location: logan, utah
Posts: 2,690
#2: Feb 10 '09

re: how to check if an excel spredsheet on a network share is already open by anther user


Most obvious way to check in vbscript is to try to save, the error I think is specific to whether the file is in use. You could clear the error and then try to save and the loop could continue until there is no error.

Jared
Reply