Industrial Automation
Industrial Automation | Europe

What is myOMRON?

Click here to find out

Search myKnowledge

Login

Username

Password



Register / Forgot password?

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
How Do I Get CX-Supervisor To Print Out An Excel Spreadsheet Using VBScript?
The following VBScript will print out the contents of a worksheet in Excel from CX-Supervisor:   ' Launch Excel dim app set app = createobject...
Why Do I Sometimes Get Run-time Error '50290' When Using CX-Server Lite in Excel?
This error can be shown when you click or edit a spreadsheet while your program is running: The error is caused by the user interface for Excel trying...
How Do I Set The Date And Time On The PC From CX-Supervisor
The following script (in VBScript) will set the date and time on the local PC clock to 13:13 on 10/10/09: Dim WshShell Set WshShell = CreateObject ("...
 
Created 2009-11-05
Modified 2010-02-25
Views 349

 

You are not logged in.