I'm trying to write few data from MSExcel to PLC tags. Here I use the DDEpoke instructions and run my macro which writes the data perfectly to my PLC. Now I want this operation to be done automatically. Whenever the values in a column changes (based on the calculations made in the previous columns) the DDE enabled macro has to run the macro for writting those tags to PLC. I tried many macros which does the autorun of macro but its either not working or I'm doing some mistake. Someone please help me on this.
codes:
Sub PLC_Transfer()
'
' PLC_Transfer Macro
'
'
' DDE_Transfer Macro
' Transfer DDE data to PLC
'
RSLinx_channel = DDEInitiate("RSLinx", "Excel")
'write data thru channel
DDEPoke RSLinx_channel, Range("X6"), Range("W6")
DDEPoke RSLinx_channel, Range("X7"), Range("W7")
DDEPoke RSLinx_channel, Range("X8"), Range("W8")
DDEPoke RSLinx_channel, Range("X9"), Range("W9")
DDEPoke RSLinx_channel, Range("X10"), Range("W10")
DDEPoke RSLinx_channel, Range("X11"), Range("W11")
DDEPoke RSLinx_channel, Range("X12"), Range("W12")
DDEPoke RSLinx_channel, Range("X13"), Range("W13")
DDEPoke RSLinx_channel, Range("X14"), Range("W14")
DDEPoke RSLinx_channel, Range("X15"), Range("W15")
DDEPoke RSLinx_channel, Range("X16"), Range("W16")
DDEPoke RSLinx_channel, Range("X17"), Range("W17")
DDEPoke RSLinx_channel, Range("X18"), Range("W18")
DDEPoke RSLinx_channel, Range("X19"), Range("W19")
DDEPoke RSLinx_channel, Range("X20"), Range("W20")
DDEPoke RSLinx_channel, Range("X21"), Range("W21")
DDEPoke RSLinx_channel, Range("X22"), Range("W22")
DDEPoke RSLinx_channel, Range("X23"), Range("W23")
DDEPoke RSLinx_channel, Range("X25"), Range("W24")
DDEPoke RSLinx_channel, Range("X25"), Range("W25")
'close dde channel
DDETerminate (RSLinx_channel)
End Sub
This is the macro I used for writing tags to PLC. Here how to add an instruction which monitors the change in the column 'W' ?
edit: here I add an eg for clear understanding
AT 00:00 AM
W X
0 Excel_TBM101
0 Excel_TBM101
0 Excel_TBM102
0 Excel_TBM103
0 Excel_TBM104
0 Excel_TBM105
0 Excel_TBM106
AT 00:05 AM
W X
0 Excel_TBM101
0 Excel_TBM101
0 Excel_TBM102
1 Excel_TBM103
0 Excel_TBM104
0 Excel_TBM105
0 Excel_TBM106
'Run PLC_Transfer macro to change the tag value of Excel_TBM103
At 00:23 AM
W X
0 Excel_TBM101
0 Excel_TBM101
0 Excel_TBM102
0 Excel_TBM103
0 Excel_TBM104
0 Excel_TBM105
0 Excel_TBM106
'Run PLC_Transfer macro for changing Tag value of Excel_TBM103
Update: I tried using following code to at least check if the code can automatically call my macro so that I can extend it for the column later, but the code doesn't seems to call my macro at all.
Private Sub Worksheet_Change(ByVal Target As Range) If Not Intersect(Target, Target.Worksheet.Range("W23")) Is Nothing Then PLC_Transfer End Sub