Determine if a file is open

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
winstein
Pro Scripter
Posts: 84
Joined: Mon Nov 26, 2012 3:44 pm

Determine if a file is open

Post by winstein » Wed Aug 02, 2017 10:46 am

There is a certain application that I would like to check on whether the file is open. Basically the macro requires that this application is open before I do anything. Otherwise, I would put the message that the program is not open.

What is the best way to approach this problem?

Thank you for reading.
PPQ

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Determine if a file is open

Post by Marcus Tettmar » Wed Aug 02, 2017 11:53 am

To check an app is open you can usually just use IfWindowOpen with the window title (or partial title). To check a file is open will depend more on how the app works, or what type of file it is. We'd need more info to figure that out.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Determine if a file is open

Post by JRL » Wed Aug 02, 2017 6:56 pm

Try ProcessExists>

Tourless
Pro Scripter
Posts: 69
Joined: Wed Jun 14, 2017 1:53 am
Location: NY

Re: Determine if a file is open

Post by Tourless » Fri Aug 04, 2017 5:14 pm

Given to me by JRL and modified to suit my specifics... basically I use this to check if quickbooks is open and if it is I close it before opening clean. If it's not open the script simply opens it. hope this helps.

Code: Select all

Let>Looptimes=0
Label>CheckQuickBooks
ProcessExists>QBW32.EXE,vQuickBooksRes
If>vQuickBooksRes=True
  KillProcess>QBW32.EXE
  Add>LoopTimes,1
  If>LoopTimes>10
    MDL>QuickBooks is failing to close.  Exiting script
    Exit>0
  EndIf
  Wait>0.5
  Goto>CheckQuickBooks
EndIf

Label>QuickBooksLogin
Let>tmp0=Q:\my qb file.qbw
ExecuteFile>tmp0,
WaitWindowOpen> QuickBooks*
Wait>3
SetFocus>QuickBooks*

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts