Question

I'm trying to access a single cell's value via maxscript and I've been having quite a bit of difficulty figuring out what exactly is keeping me from doing so. Here's what I have in maxscript:

-- Startup Ops
-- Generate a filename
excelFile = "<path string>\testbook.xlsx"

-- Start an Excel OLE Object
x = CreateOLEObject "Excel.Application"

-- Create a new workbook in the new excel document
x.application.Workbooks.open(excelFile)

-- This makes Excel Visible
x.visible = true



--Here's where I'm having trouble
-- Retrieve the contents of Cell A3
contents = x.ActiveSheet.Cells(3, 1).Value

-- Change the contents of Cell A3 to Hello
x.ActiveSheet.Cells(3, 1).Value = "Hello"



-- Cleanup Ops
-- Close the spreadsheet
x.application.ActiveWorkbook.Close

-- quit excel
x.quit()

-- Release the OLE Object
releaseOLEObject x

-- Release ALL OLE Objects, just in case
releaseAllOLEObjects()

Here's the msdn resource I used to for reference. As far as I know, I followed everything to a T. If anyone could help out, I'd really appreciate it.

Was it helpful?

Solution

I don't have Excel at hand but I believe it should rather be (x.ActiveSheet.Cells X Y).Value.

Either that or you can take a different route, use .NET and excellibrary.

OTHER TIPS

I just wanted to add a solution here that worked for me. I know this was 7 years ago and I'm certain you solved the problem, but your code really helped me and I couldn't find anywhere anything similar, so here it is:

--Here's where I'm having trouble
-- Retrieve the contents of Cell A3
contents = x.ActiveSheet.Cells(3, 1).Value

-- Change the contents of Cell A3 to Hello
x.ActiveSheet.Cells(3, 1).Value = "Hello"

I used:

contents = x.application.cells 3 1  
contents.value = "Hello"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top