Read data by button in Excel

Yasamalian99

Member
Join Date
Sep 2023
Location
Baku
Posts
1
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
 
Last edited:

Similar Topics

Hi Iam using monitouch hmi(V9 soft) with omron plc cj2m (CX programmer). In this I want to read a data from hmi to plc. The data was like...
Replies
0
Views
101
Thank you for any and all responses/help. I have an RSLogix 5000 v20 and a Cognex In-Sight v5.9 spreadsheet (8502P). I can not figure out how to...
Replies
0
Views
133
Dear Experts, Please, kindly guide me through how to read data from ABB PLC to S7-1200 Siemens PLC. I want to use Siemens S7-1200 PLC to read data...
Replies
1
Views
450
Dear colleagues, I am reaching out for assistance with an issue I am having. I have a code that can successfully insert data from FactoryTalk...
Replies
6
Views
1,058
Hello everyone, I'm working with an old ACM3710 device and I'm encountering an issue with the data frames I'm sending over an RS232 connection...
Replies
5
Views
683
Back
Top Bottom