Jump to content
TheGreenGentleman

VB Script That Detects if A Specific Excel File is Open

Recommended Posts

Hi Guys,

 

I'm trying to move away from Task Scheduler as my trigger for opening an Excel file. The problem there is it has a minimum of 5 min interval (I need at least 30 sec) and If the process of the initial instance of the Excel file is longer than the usual that after 5 min another instance executes it messes up my memory bandwidth. What I want is to use VB Script that first check if a particular Excel file is open if yes then wait for another 30 sec to check.Question: What is the right syntax/code for detecting a specific Excel file and loops every 30 sec. But I also want to be able to end the loop if I want to.Here is my current code:

Gateway TimeoutRequestURI=http://timeentry/Set Recordset = CreateObject("ADODB.Recordset") ConnString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=PHMNWWKS027604; DATABASE=db_skusetup; " &_"UID=root;PASSWORD=; OPTION=3"'Check for Export Query'Recordset.ActiveConnection = ConnString exportSQL = "SELECT * FROM tb_queue_export WHERE request_status = 'Pending' ORDER BY request_id DESC LIMIT 1"Recordset.Open exportSQLSet objExcelExtract = CreateObject("Excel.Application")Set objWorkbookExtract = objExcelExtract.Workbooks.Open("C:Usersushuam00DesktopLAPTOP.xlsx")	If objWorkbookExtract.ReadOnly then		if Recordset.Fields(3) <> "" then					end if	end iftest= MsgBox(Recordset.Fields(3),3,Recordset.EOF)Recordset.Close

ReadOnly is not doing it for me.

Share this post


Link to post
Share on other sites

It looks like there is a discussion here:https://social.technet.microsoft.com/Forums/en-US/436f3c51-b05d-41b5-91da-066b54fdfee2/check-if-the-file-is-open-using-vb-script?forum=ITCGIt looks like you can use the WScript.Sleep method to tell your script to sleep for a certain number of milliseconds.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×