3

I have a vbs script which writes to an Excel spreadsheet. To be able to save the spreadsheet I need to ensure that it is not already open.
Can someone suggest the best way to do this?

Some research:

  • I tried to create a Word Tasks objects to show me all running processes, but on Windows 7 it only tells me whether Excel is running or not.
  • Creating an Excel.Application object does not give me access to all running instances of Excel.
  • I thought about opening the spreadsheet for writing but the only way I can think of doing this is with the File System Object OpenTextFile method which does not seem to be the correct approach as the Excel file is a binary.

Any other ideas?

Lance Roberts
  • 22,383
  • 32
  • 112
  • 130
DavidA
  • 33
  • 1
  • 4
  • As for the running processes, check out this thread to determine what processes are running and who started them: http://stackoverflow.com/questions/76275/how-can-i-kill-a-process-using-vbscript-started-by-a-particular-user/89397#89397 – unrealtrip Oct 11 '10 at 15:07

1 Answers1

0

Since the Excel.Application object doesn't give you access to all instances of Excel, what about using a simple error trap? ie. if it is unable to save the file, throw a warning message, save as another file name, etc.

unrealtrip
  • 670
  • 4
  • 13