Professional Communication
Software Development Tools

OPC Foundation member and certified logos

Online Forums

Technical support is provided through Support Forums below. Anybody can view them; you need to Register/Login to our site (see links in upper right corner) in order to Post questions or issues. You do not have to own a commercial license in order to use the OPC Labs supportOur team is actively monitoring the forums, and provides replies as soon as possible.

Please read Rules for forum posts before reporting your issue or asking a question. OPC Labs team is actively monitoring the forums, and replies as soon as possible.

Various technical information can also be found in our Knowledge Base. For your convenience, we have also assembled a Frequently Asked Questions page.

Do not use the Contact page for technical issues.

Looping with the RTD function

More
29 Jan 2026 10:46 #14561 by support
Hello.

I think that there are actually 2 issues in your post:

1. Why the Excel closes or crashes with the code you provided.
2. Is the code you provided actually going to do what you want, if it worked?

At the moment I have doubts about #2, and it makes no sense to go deeper into #1 without having #2 clarified first.

The RTD function is special in that its result can change dynamically. That works in a formula in a cell. If you, however, evaluate that function inside the VBA code, you end up with a static value (number, typically). Your code then assigns this value to the cell. So if the code had worked, in the best case, you would end up with cells filled with static OPC values valid at the time you ran the code.

If your intent was to end up with cells that contain dynamic data, your code should set the *formulas* inside the cells (and the formulas should contain the RTD function), and not the *values* of the cells.

Let me know if I got it wrong or if you need further help.

Best regards
 

Please Log in or Create an account to join the conversation.

More
28 Jan 2026 20:02 #14560 by glenn@awscontractorsinc.com
I'd like to loop through some tags in an array in a PLC and populate an Excel Sheet with that data.  It's basically a 12 x 50 array. I could type "=RTD.....whatever" in all 600 cells, but it would be way easier if I could do it programatically.  I can't seem to crack this one.  Using a code loop, I can loop it once using variables in the RTD strings indexed by the loop count.  I can NOT get it to work if I loop more than once.  I suspect it has something to do with the asynchronous communications of the RTD function.  The following VBA code works with an index of 1 (one loop).  If index is greater than 1, Excel thinks about it a bit, shuts itself down and then reopens in recovery mode.  Any ideas?

Sub RefreshRTD()
    For Index = 1 To 1  'Change this loop upper limit to 2 and Excel crashes'
        
        topicstring1 = "nsu=CODESYSSPV3/3S/IecVarAccess ;ns=4;s=|var|Turck/ARM/WinCE TV.Application.GVL.RandomNum[" & Index & "]"
               
        ActiveSheet.Range("D" & Index).Value = Application.WorksheetFunction.RTD("opclabs.office.excel.connectivityrtdserver", "", "opcuaattribute", _
        "opc.tcp://192.168.2.201:4840/UADiscovery", topicstring1, "", "", "Value;""""")
     
    Next
End Sub

 

Please Log in or Create an account to join the conversation.

Moderators: supportvaclav.zaloudek
Time to create page: 0.116 seconds