Jump to content
Sign in to follow this  

Opening an Excel File in Readonly mode

Recommended Posts


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)

Share this post

Link to post
Share on other sites

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")
MsgBox(0, "", "File is not in use")
Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

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
Sign in to follow this