How To Read And Write To Excel Cells From CX-Supervisor

Plant data can easily be collected by CX-Supervisor, but extra data analysis often requires data to be exported or imported from a spreadsheet like Microsoft Excel. For large amouts of data you can set up Data Logging.  To access a few cells of data though you can use a Microsoft ActiveX control to read and write direct to cell values.

By using a VBScript action (e.g. on a button) you can create an object to access the Excel application and workbooks. The code below creates a connection and then sets the value of a chosen cell. "CellonExcel" and "ExcelSetPoint" are the only CX-Supervisor points requiring definition as text points:

' Launch Excel
set app = createobject("Excel.Application")

' Load a workbook
set wb = app.Workbooks.Open(s_ProjectPath + "\excelsheet.xls")

'define the cell you wish to use
set rng = wb.Activesheet.Range(CellonExcel)

'apply the value to the cell
rng.value = ExcelSetPoint

'Save, close, quit and tidy up - to avoid Excel hanging around in background

set rng = nothing
set wb = nothing

set app = nothing

A demo project (saved in CX-Supervisor v3) is also attached showing reading a cell, and viewing the workbook.
For more information on Microsoft's control to access Excel check out the Microsoft web site or try Googling for examples of using CreateObject for Excel for other examples.