Member Login
Search
Jump to a Date
Sponsored Communities
Cool stuff
Neat Stuff

Visit our shop for nerds in control lifestyle products.
Thermal Overload
The threads that wouldn't die...
- PC reliability?
- Windows, real time
- PID loops
- PCs vs. PLCs
- Replacing people
- MS 'monopoly'?
- Software quality
- Where do we go from here?
- Why pay?
- PC reliability?
- Windows, real time
- PID loops
- PCs vs. PLCs
- Replacing people
- MS 'monopoly'?
- Software quality
- Where do we go from here?
- Why pay?
Fortune
Greener's Law:
Never argue with a man who buys ink by the barrel.
Never argue with a man who buys ink by the barrel.
RSS Feed
www.control.com/rss/
To get a personalized feed, become a member at no cost.
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!
Thanks for the help!
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
Kevin
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
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
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
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
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.
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- Pepperl+Fuchs acquires Christensen Display Products
- Automation and Ethernet Combine for 3D Disney Attraction
- Advantech: Ethernet switches; touch panel, embedded computer; develop better GUIs
- MESA International event marked by change, sustainability, SOA
- Compressor control: Controller provides live view of compressor performance
- Upgrading Control: Migration or Evolution?
- HMI/SCADA: Microsoft Fluent technology helps enhance Proficy iFIX 5.0
- Integrating Environmental Processes
- HMIs: NASCAR pit crews, Vista users get Simatic options
- HMI: Monitors, graphic panel improve images, offer ruggedness
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.
Our Advertisers
Help keep our servers running...
Patronize our advertisers!
Patronize our advertisers!




