Instrument Control (GPIB, Serial, VISA, IVI)

cancel
Showing results for 
Search instead for 
Did you mean: 

viOpen is not defined in my VBA code

Solved!
Go to solution

I download NI-VISA 4.6.2 and wrote a VBA code to use NI-VISA to control Anritsu VNA.

 

my code is

 

status = viOpen ( defaultRM,"TCPIP::".........)

 

VBA program shows a compile error: Sub or Function not defined ( viOpen is highlighted)

 

I think I miss something in my Reference but don't know which one. I include all files seem related to NI-VISA in my reference.

 

Thanks

 

 

0 Kudos
Message 1 of 10
(6,306 Views)
Can you tell us the exact error message that you are getting? Is it "symbol undefined"? Did you link visa lib?
0 Kudos
Message 2 of 10
(6,292 Views)

VB program shows

 

" Sub or Function not defined "   and the viOpen is highkighted.

 

I am not sure I link all VISA lib. How to check it ?  Thanks

0 Kudos
Message 3 of 10
(6,280 Views)
Solution
Accepted by topic author xinli
I found the problem. I need in Tool/Reference add VISA32.dll from NI VISA.
0 Kudos
Message 4 of 10
(6,271 Views)
I suppose that is what i meant. Never the less glad you found the solution...:smileywink:
0 Kudos
Message 5 of 10
(6,253 Views)

Hello,

I know this post has 10 years, but, in fact I have the same problem.

I am not used to program using VBA in Excel, nor using VISA.

I just want to parameter my Rigol DG822 arbitrary generator.

At first, I installed the NI-VISA suite, in the VBA references, I activated VISA-COM 5.12 Type Library and VISA-COM 488.2 Formatted I/0 5.12.

 

My code is simply issued from the Rigol DG800 programming manual : 

 

Sub QueryIdn()
Dim viDefRm As Long
Dim viDevice As Long
Dim viErr As Long
Dim cmdStr As String
Dim idnStr As String * 128
Dim ret As Long

'Turn on the device, and the device resource descriptor is in CELLS(1,2) of SHEET1'
NO_LOCK, 0, "")
viErr = visa.viOpenDefaultRM(viDefRm)
viErr = visa.viOpen(viDefRm, Sheet1.Cells(1, 2), 0, 5000, viDevice)

'Send request, read the data, and the return value is in CELLS(2,2) of SHEET1'
cmdStr = "*IDN?"
viErr = visa.viWrite(viDevice, cmdStr, Len(cmdStr), ret)
viErr = visa.viRead(viDevice, idnStr, 128, ret)
Sheet1.Cells(2, 2) = idnStr

'Turn off the device'
visa.viClose (viDevice)
visa.viClose (viDefRm)
msg.Close
End Sub

 

In Cell 1.1, I have  USB0::0x1AB1::0x0643::DG8A224203417::INSTR

 

In F8 line-debugging, it stopped at the the first VISA commande (visa.viOpenDefaultRM(viDefRm)), saying "object required / error 424".

OK, error 424, means the VISA commande is not understood. And so what do I need more than the reference activated to do that ?

 

In C:\Windows\System32, I have visa32.dll and visa64.dll.

But, the VISA-COM reference in VBA does not point on one of these files, but on C:\Program Files\IVI Foundation\VISA\VisaCom64\GlobMgr.dll, and I am not allowed to changed that.

 

May someone good help a poor crying man ?

Thank you very much for the knowledge :

Best regards

Fred8

0 Kudos
Message 6 of 10
(3,394 Views)

I also ended up in exactly the same situation with a slightly different model.
The issue seems to be some changes in the NI VISA API, so VBA does not work anymore.
Any suggestions on how to use the API would be appreciated. Thanks.


Zoltan

0 Kudos
Message 7 of 10
(2,679 Views)

As it seems this API is completely abandoned / probably never worked / definitely not easy to use -if a standalone software is suitable, then I would recommend to use UlterPower from the Rigol website: https://www.rigolna.com/download/

I saw some reported problems with it, but worked for me.

0 Kudos
Message 8 of 10
(2,666 Views)

Hello. ZoltanMTS.

The Excel VBA measurement program I created still works with NI-VISA.
It works fine with the latest NI-VISA 21.5 as of today.

Please note that if you are using Microsoft 365, there is a version that does not work due to a bug on the Office side, so you need to update to 16.0.14827.20192 or higher.

https://docs.microsoft.com/en-us/officeupdates/update-history-office-2019

Message 9 of 10
(2,639 Views)

Hi Iwa6,

 

Thanks for your reply. This is a problem I face quite frequently: there is a nice software, which I would like to use, but I cannot make it work and I cannot find information about restrictions or incompatibilities.

I appreciate, there are too many versions to test for incompatibilities, but it is frustrating for the users / developers to face this kind of problems.

 

I saw I was not the only one with this problem, that is why I sent out a new message.

Thanks to clarify it, it may be useful for someone else in the future.

 

Zoltan

0 Kudos
Message 10 of 10
(2,617 Views)