- Posts: 6
- Thank you received: 0
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. You do not have to be a licensed user of our product.
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.
Read multiple values in VBA
- dani.hartman@metronik.si
-
Topic Author
- Offline
- Senior Member
-
Thank you very much for your help.
Best regards.
Please Log in or Create an account to join the conversation.
The code looks like this:
Best regards
Please Log in or Create an account to join the conversation.
- dani.hartman@metronik.si
-
Topic Author
- Offline
- Senior Member
-
- Posts: 6
- Thank you received: 0
I've tried to do the similar before - I used the code from other examples but I always got somekind of error.
Now I tried the code from your VB6 example, which is almost like VBA, but when it tries to read (Client.ReadMultiple(arguments)) I get an error:
Run-time error '91'
Object variable or with block variable not set
There is my sample code below. Could you please give me a hint what am I doing wrong

Sub Multipla()
Dim Client As EasyUAClient
Dim ReadArguments1 As New UAReadArguments
Dim ReadArguments2 As New UAReadArguments
Dim ReadArguments3 As New UAReadArguments
If OPCUAServer = "" Then
ReadOPCUAProps
End If
ReadArguments1.EndpointDescriptor.UrlString = OPCUAServer
ReadArguments1.NodeDescriptor.NodeId.expandedText = OPCUATagPrefix & "dbAnalogSensors.TIC_01_29.ScaledMax"
ReadArguments2.EndpointDescriptor.UrlString = OPCUAServer
ReadArguments2.NodeDescriptor.NodeId.expandedText = OPCUATagPrefix & "dbAnalogSensors.TIC_01_30.ScaledMax"
ReadArguments3.EndpointDescriptor.UrlString = OPCUAServer
ReadArguments3.NodeDescriptor.NodeId.expandedText = OPCUATagPrefix & "dbAnalogSensors.LI_01_37.ScaledMax"
Dim arguments(2) As Variant
Set arguments(0) = ReadArguments1
Set arguments(1) = ReadArguments2
Set arguments(2) = ReadArguments3
' Obtain values. By default, the Value attributes of the nodes will be read.
Dim results() As Variant
results = Client.ReadMultiple(arguments)
End Sub
Please Log in or Create an account to join the conversation.
you are right that this example is missing - it is simply due to the sheer amount of combinations we would have to write.
There are, however, related examples that may help you.
First, there is an example for reading multiple values in Excel VBA - but for OPC Classic. It is in file ReadAndDisplayMultipleValues.xls, and looks like this:
Second, there are examples for reading multiple UA values in VB 6, which should be very close to VBA. They are under VB\VB60\UADocExamples, in EasyUAClientForm.frm; you can open it with a text editor, without having VB6. For convenience, here are they:
If the examples don't help, please post your code and the error you are getting.
BTW, have you considered whether the Excel Option would not be an easier solution? (of course VBA is more powerful - it depends on the usage case).
Best regards
Please Log in or Create an account to join the conversation.
- dani.hartman@metronik.si
-
Topic Author
- Offline
- Senior Member
-
- Posts: 6
- Thank you received: 0
Could you please send me an example how to read multiple values from OPC UA server in VBA code. I couldn't find this kind of example among the other Excel examples and the description in help is also not detailed enough for VBA code…
I'm strugling with this issue for some time now and I always get some kind of VBA error. Otherwise reading and writing one value and also subscribing to multiple values works fine.
Thank you in advance and best regards
Please Log in or Create an account to join the conversation.