Industrial Automation
Industrial Automation | Europe

myKnowledge

Main > Product Type > Software > Visualisation
Minimize Text   Default    Enlarge Text
 

Print
E-mail

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


Introduction
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.
Method

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
app.ActiveWorkbook.Save
app.Workbooks.Close

set rng = nothing
set wb = nothing

app.Quit
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.

 

 

 

 

 



Attachments

Accessing_Excel.zip - Size: 410700


Comments (View All Comments / Add Comment)

Related Articles
No related articles found.
Created 2009-11-05
Modified 2010-02-25
Views 9920

 

You are not logged in.