Opening and xls or xlsx file

Opening and xls or xlsx file

Ray.Collett
Explorer Explorer
561 Views
3 Replies
Message 1 of 4

Opening and xls or xlsx file

Ray.Collett
Explorer
Explorer

I'm writing a tool to pull in data from an Excel file, and I am looking for some help understanding how to better control error situations.  Currently I have these lines:

 

xlsFile = CreateOLEObject "Excel.Application"
openFileResult = xlsFile.application.Workbooks.open("C:\MyFile.xls")
(xlsFile.application.Worksheets("My Sheet")).Activate

 

 

How would I check for errors on any of these lines?  Specifically, I keep getting errors on line 2 if I already have that sheet open in Excel.  I see on the help file Workbooks.Open that there are options to open it as read only, but for the life of me I can't figure out a syntax in my Maxscript to pass the ReadOnly flag.  Additionally, how do I check to see if the OLE application is ready after line 1 finishes, and how to I check to see if I was successful with the active sheet switch?

 

Thanks!

  Ray

 

 

0 Likes
562 Views
3 Replies
Replies (3)
Message 2 of 4

denisT.MaxDoctor
Advisor
Advisor

Do you really need a real-time response to any changes to the XML file? Isn't it easier and enough just to parse the file and get all the necessary data?

0 Likes
Message 3 of 4

Ray.Collett
Explorer
Explorer

Hmm, I didn't say anything about real-time responses to changes.  That's not at all what I'm asking about.  I just want to make my script more resilient to connection errors.  With more native maxscript file open commands, you can check to see if the file pointer is valid before trying to read the data, that's basically what I'm after.  The part about wanting to open it in read only mode is in case I just happen to have it open, or someone on the network has it open.  Not for any real-time thing.  Although, that could be cool.....  🙂

 

 

0 Likes
Message 4 of 4

denisT.MaxDoctor
Advisor
Advisor

I just want to say that might be easier to use some open source code and dlls to read XLS file data... for example ExcelDataReader 

0 Likes