positano Posted January 24, 2013 Share Posted January 24, 2013 Help! I searched the forums and help file and did not find an answer to my question. I'm attempting to open an Excel file and print it using an AutoIt script. Works great unless somebody else has the file open. In that case, I get an "file in use, try again later" message from Excel. I thought I'd be able to open it in readonly mode to avoid this error (see code below). But it doesn't work! What am I doing wrong? Thanks in advance for your help. #Include <Excel.au3> $Readonly = True $oExcel = _ExcelBookOpen("G:\MyExcelFile.xlsx", 0, $Readonly) Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted January 24, 2013 Moderators Share Posted January 24, 2013 (edited) Hi, positano, welcome to the forum. Not sure what version of Excel you're using; from 2007 on I thought the message was that the file is open and gave you the option of opening read-only, notifying the user, or closing. If you'd like to just check whether the file is in use, you could do something like this: $oExcel = ObjCreate("Excel.Application") $oBook = $oExcel.Workbooks.Open(<path to file>) If $oBook.ReadOnly Then MsgBox(0, "", "File is in use") $oExcel.Workbooks.Close Else MsgBox(0, "", "File is not in use") $oExcel.Workbooks.Close EndIf Edited January 24, 2013 by JLogan3o13 "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now