Instrument Control (GPIB, Serial, VISA, IVI)

Showing results for 
Search instead for 
Did you mean: 

viOpen is not defined in my VBA code

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.





0 Kudos
Message 1 of 6
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 6

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 6
Accepted by xinli
I found the problem. I need in Tool/Reference add VISA32.dll from NI VISA.
0 Kudos
Message 4 of 6
I suppose that is what i meant. Never the less glad you found the solution...:smileywink:
0 Kudos
Message 5 of 6


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)
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


0 Kudos
Message 6 of 6