Member Login
member
passwd
remember me on
this computer.

- join now -
- forgot username or password? -

Search

Jump to a Date

Sponsored Communities
Cool stuff
Select a topic of interest:
...and press:
Neat Stuff
Control.com Stuff

Visit our shop for nerds in control lifestyle products.

Fortune
Greener's Law:
Never argue with a man who buys ink by the barrel.
RSS Feed
RSS feed Use this link to get an RSS feed of the Control.com article flow, for private, non-commercial use only:
www.control.com/rss/
To get a personalized feed, become a member at no cost.
Select a Page Style
Select one of the following styles:
- BluFu
- Classic
(cookies required)
advertisement
from the Automation List department...
Writing data from RSView SE to an XLS file using VBA
Human-Machine Interface and SCADA. topic
Posted by Carlos Cordova on 8 July, 2007 - 9:06 pm
I'm trying to make a VBA code capable of taking a tag from RSView SE and then write it into a XLS file. The problem is that I've been looking for the correct way to manipulate Excel objects in RSView, But I can't find so much information about it. Can sombody tell me how to create workbooks, sheets and write to them and save a XLS file using VBA in RSView SE???

Thanks for the help!


Posted by Kevin on 22 July, 2007 - 10:12 am
I think the easiest thing to do is have Excel installed on the PC, then write the VB to open excel (in the background) modifie the cells then close it again. This way you wont have to worry about excel's file format.

Kevin


Posted by Kevin Grey on 28 July, 2007 - 2:04 pm
Hi,
Reading tags from RSView is not the easiest SCADA, but the VBA part to write to Excel and other objects is the same as any other. The key is to use Set ObjExcelApp = CreateObject("Excel.Application") to create an object instance of excel. Try embedding this into a vba action behind a button press;

private sub Button_press()

on error goto ErrorHandler

'Best to define variable first but not nessecary
Dim ObjExcelApp as object
Dim Fname as string

Fname = "C:\Test.xls" 'name of already created excel project

Set ObjExcelApp = CreateObject("Excel.Application")
ObjExcelApp.visible = false 'make run in background


ObjExcelApp.Workbooks.Open(Fname)

ObjExce lApp.Worksheets("Worksheet1").cells(1,"A").value = "123" 'Write date to cell A1

'you can read the propities of an object on a screen without reading from a tag
'ObjExcelApp.Worksheets("Worksheet1").cells(1,"A ").value = Me.elements("Numeric_input1").value

'use this to run an excel macro
'ObjExcelApp.run("Macro_Name")

'save and exit excel
'I have had problems with silenty saving and closing Excel, this seems to vary from application to another, try;
ObjExcelApp.ActiveWorkbook.Save
ObjExcelApp.Workbooks.Close
ObjExcelApp.quit
Set ObjExcelApp = Nothing

exit sub

Error_handler
' write error to factory talk
LogDiagnosticsMessage Err.Number & " " & Err.Description, ftDiagSeverityError

end sub

private sub Button2_press()
'open an new excel project


'Best to define variable first but not nessecary
Dim ObjExcelApp as object
Dim Fname as string

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True
objExcel.Workbooks.Add
objExcel.Cells(1, 1).Value = "Test value"

ObjExcelApp.ActiveWorkbook.SaveAs(Fname)
ObjExcelApp.WorkBooks(Fname).close(False)
ObjExcelApp.quit
Set ObjExcelApp = Nothing

end sub

I think the syntax is correct, if not very close (I do not have RSview installed at the moment). A good trick is to use VBscript and try it out on a pc first (you will not be able to access any RSView objects). Create a file with a .vbs extention and run the program (with out the 1st and last line and the dims).
If you need any other help let me know.

Kevin


Posted by Flash on 15 December, 2007 - 2:41 pm
Hi Kevin,
Do you have any code to take the data from an rslinx cell in excel and save that data every time the value changes to a column of data for unattended data collection. Source data is a test result integer file in a SLC500. I know how to get the data into excel, But I dont know how to save the data when it changes on the next test. Let me know PJ

pj_gordon@hci.hi-lex.com


Posted by sreeraj on 16 December, 2007 - 5:37 pm
hi
I have tried this one by configuring DDE client that comes along with RsLinx long ago.I dont have rslinx now. But u will get commands to be entered from Excel's DDE help.

From Control Engineering magazine...
Related articles from Control Engineering magazine
Above articles copyright 2008 Reed Business Information. Subject to its Terms of Use.
Your use of this site is subject to the terms and conditions set forth under Legal Notices and the Privacy Policy. Please read those terms and conditions carefully. Subject to the rights expressly reserved to others under Legal Notices, the content of this site and the compilation thereof is © 1999-2008 Control Technology Corporation. All rights reserved.

Users of this site are benefiting from open source technologies, including PHP, MySQL and Apache. Be happy.

Internet Explorer 6.0 Fix

Advertisement
Our Advertisers
Help keep our servers running...
Patronize our advertisers!