Writing to PLC Tags on OPC Server Using Excel VBA

SoupMan

Member
Join Date
Jun 2021
Location
Pennsylvania
Posts
1
Hello, I am looking for help writing to PLC tags from Excel. I am using Factory Talk Gateway as an OPC server and Excel VBA to write out to an Allen-Bradley PLC. AB has an example in their knowledgebase on how to read tags, but they don't show how to write to tags. If anybody has experience writing to PLC tags I would appreciate some help. Thank you
 
Here is some code I did to write 250 parameters into a few hundred tags.
I populated the data to write on a sheet and used a pushbutton to activate it.
Works great, no fat fingering data into the PLC Tags.
The cell stuff was just so I could watch the progression.
It also wrote data to another sheet that did not get populated. Kind of a self check.

Private Sub CommandButton21_Click()

'Set up Counter for the For/Next Loop
Dim LCounter As Integer
Dim Test As Integer

'Open the DDE Channel to the ControlLogix Processor via RSLinx Topic
DDEChannel = Application.DDEInitiate(app:="RSLinx", topic:="YourTopic")
'Begin For Next where the Tags begin at row 3 and end at row 253
For LCounter = 3 To 253
'Define the Tag as a DDEItem and where it is located so the first tag is at Cells(Row3(variable LCounter), ColumnC(3))
DDEItem = Cells(LCounter, 3).Value
Cells(1, 1).Value = DDERequest(DDEChannel, DDEItem)
Cells(1, 13).Value = DDEItem
Cells(1, 12).Value = DDERequest(DDEChannel, DDEItem)
If CInt(Cells(1, 1).Value) >= 0 Then
'Set the RangeToPoke where the data has to be converted to a range and the cell the data is in is the variable row LCounter column H (8)
Set RangeToPoke = Worksheets("Sheet2").Range(Cells(LCounter, 8), Cells(LCounter, 8))
'Poke the Data from Range to Poke
Application.DDEPoke DDEChannel, DDEItem, RangeToPoke
Else
Debug.Print (DDEItem)
Sheets("NoDataTagList").Cells(LCounter, 1) = (DDEItem)
End If
'Step the counter and do it again
Next LCounter
'When the Counter finishes (256) terminate the DDE Connection\
Application.DDETerminate DDEChannel

End Sub
 
There are examples in the RSLinx help file. Just search VBA and you'll see read and write code examples.
 

Similar Topics

I'm currently a senior in college working on a senior design project involving PLCs and Raspberry Pi. We have data taken using the PLC that we...
Replies
14
Views
4,049
Hello, i am currently trying to create a plc programme from my Tia portal v16 for a package filling machine. But i am kinda new to the plc stuff...
Replies
48
Views
17,272
i am new to these things. I have no intention of using this in a commercial way whatsoever. I wanted to write a small plc programme for myself. We...
Replies
18
Views
7,837
HI all, I have a CP1L PLC programmed with Omron CX-one and I need to adjust the internal real time clock externally, i.e get my PLC code to set...
Replies
1
Views
1,654
What are you guys using to visualize a program before writing it? Are you using some kind of flow-chart software? I need to step up my...
Replies
8
Views
2,439
Back
Top Bottom