1

i am trying to make a script that would be run every 5 minutes by windows task scheduler, the script is pretty much done, but with one flaw. Script runs the macro inside a exel file on local server storage but i dont know how to check if someonne has the file opened? it should be really simple actually, if file is already opened then skip code. that way the script wont bother annyone that is at the moment working on the file.

here is my script:

Option Explicit
On Error Resume Next
Test

Sub Test() 
    Dim XL 
    Dim WBK

    Set XL = CreateObject("Excel.Application")
    Set WBK = XL.Workbooks.Open("C:\Users\Mobilefreek\Desktop\MFT_Vnosi_Test.xlsm")

    XL.Run "MFT_Izracun"

    WBK.Save
    WBK.Close

    Set WBK = Nothing
    Set XL = Nothing
End Sub 
Uroš Grum
  • 138
  • 2
  • 14

1 Answers1

0

Check if a specific Excel file is open when several Excel files are open and activate it

The above link might help.

Set WshShell = WScript.CreateObject ("WScript.Shell")
if WshShell.AppActivate(ExcelFileName) = True then
XL.Run "xxxx"
else
Test
End if
Community
  • 1
  • 1
Sujith
  • 51
  • 1
  • 7
  • I think the OP was worried if someone **else** had the file open; not if it was still open in the server's environment. –  Dec 03 '15 at 08:20
  • yes ... at the moment it opens file , runs the script, but when it tries to save the user, if he at that moment has the file open gets a prompt that the file already exists and if he wants to replace i, i would rather the user be uninterupted so the file would just skip thet round and try in the next 5 minutes – Uroš Grum Dec 03 '15 at 08:37