Excel file open?

I’m using Excel automation to read an Excel workbook into a database. However, I noticed that if the Excel file is opened (in Excel), the import fails but does not provide an error message. Nothing gets imported.

Is there a way to tell if the Excel file is opened in Excel?

We are developing this for end users so we have to try and protect against this happening because they’ll never figure out what went wrong.

Hi John,

Try with this code before your process:
-------------------------------------------------------->

Dim i as Integer

For i = 1 To Excel.Workbooks.Count

MsgBox Excel.Workbooks(i).Name

Next

Check the workbook name that you want to open.

A complete code …
-------------------------------------------------------->

Dim i as Integer

For i = 1 To Excel.Workbooks.Count

if Excel.Workbooks(i).Name=yourbook then
Excel.Workbooks(i).Close
Exit
Endif

Next

…your next code

Elvis - Worked like a charm. Weird that “Name” does not show up as a property that you can reference but it still works. Thank you.

Eugene Dakin has a book on how to program Excel with Xojo/RealStudio. I recommend it, he took the time to document all the undocumented little tidbits like this…

I can agree with Joseph. Eugene really has an understanding of interfacing xojo and office. He is really helpful as well when you need help.