I know this seems like an easy one but I've tried 2 things already and neither worked. What's special about this situation is that I have a batch file triggered by emails coming into outlook. Most of the time the emails are triggered at the exact same time so Outlook could receive 10 emails at once therefore executing the batch file 10 times within a span of 2 seconds. The only objective is to open an excel file when the first email comes in and for every email thereafter do nothing since the excel file is already open.
The first method I tried was to test if the file was open by attempting to "copy" it into another location:
echo.N|copy /-y NUL "P:\Pricing\Pricing Templates\Pricing Models\trial\LP3 Model vcongestion outlook.xlsm">NUL&&(
echo.LP3 Model v7c.xlsm is free!
start excel "LP3 Model vcongestion outlook.xlsm"
) || (
echo.LP3 Model vcongestion outlook.xlsm is in use!
)
This sometimes, but didn't always work because there could be a 1 second buffer between the time the first file executed and the time the file was open and therefore locked for copying. Therefore I instead tried to simply test whether the application of Excel was open
tasklist /nh /fi "imagename eq EXCEL.exe" | find /i "EXCEL.exe" > nul &&(
echo found
)|| (
start excel "P:\Pricing\Pricing Templates\Pricing Models\trial\LP3 Model vcongestion outlook.xlsm"
)
However I'm getting the same thing for presumably the same reason. Are there any alternatives to this?