Read data by button in Excel

Hello, I want to send the data from Rslogix500 to Excel. I created a connection between RSlinx and Excel. The values in Excel automatically change. But I need to control it by button in Excel. I think I need to write a code in Excel VBA. I need help. Thanks in advance.
 
Long time since I used DDE in excel but it might be something like this
On the button sub open the connection, check for error, if not do a DDE.Request, then close the connection

Sub Button1()
On Error Resume Next
'Open the connection to RSLinx
OpenRSLinx = DDEInitiate("RSLinx", "PLC")
' get the value
Value = DDERequest(rslinx, "Tagname.Value")
'Note: Value could be a cell.
Cloe the connection
OpenRSLinx = 0

'Check if the connection was made
If Err.Number <> 0 Then
MsgBox "Error Connecting to topic", vbExclamation, "Error"
OpenRSLinx = 0
End If

End Sub

Note:Those in red are the connection strings etc. you will have to set up the connection strings to what you have set in RSLinx.
As I said, long time so there could be typo's in the above code it's off the top of my head.
 
Yes, you have to use DDE poking to control the process from Excel. This is if you are wanting to write data to the PLC. If you are wanting to retrieve it you can do much the same, but source and range being the PLC and target being the worksheet. Identify your Dim's (Source, Target, Channel, Item, Range).

So.. to write

Sub XXXXXX()
Dim Source As Range
Dim Target As Range
Dim DDEChannel as Long
Dim DDEItem as String
Dim RangeToPoke as Range

DDEChannel = Application.DDEInitiate(app:="RSLINX", topic:="XXX")
DDEItem = "Tag name,L1,C1"
Set RangeToPoke = Worksheets("SheetX") .Range("CELL")
Application.DDEPoke DDEChannel, DDEItem, RangeToPoke
Application.DDETerminate DDEChannel
End Sub

Don't forget to set your target.


To read

Sub XXXXXX()
Dim DDEChannel As Long
Dim ItemName As String
Dim Result As Variant

DDEChannel = Application.DDEInitiate("ServerAppName", "ServerTopic")

ItemName = "tagname,L1,C1"

Result = Application.DDERequest(DDEChannel, ItemName)

Application.DDETerminate DDEChannel
End Sub
 

Similar Topics

Ive seen both accepts Modbus TCP/IP so how can I read data from one controller Master MICRO850 Cliente - S7-1200
1
Replies
279
Views
I have bought an IFM O3M372 and I wanted to read some data from a PLC S7-1200 I read it with Trcv and Tsend so if anyone has read something about...
2
Replies
332
Views
Hello all. I added a devicenet module on my network, everything went fine. I can see the device properly, properly download to the scanner, but...
5
Replies
498
Views
Hello, I got an Rockwell point-io adapter 1734-AENT/C adapter with a 1734-IK/C on slot 2. Its especially the parameters in Assembly123 of the...
0
Replies
517
Views
I have a quesiton regarding data access and modify variables from plc , i know for newer versions S7 1200 and 1500 plcs we have OPC server and...
3
Replies
724
Views
Top