Visual Basic for Excel, Simple Example Program to Control Instruments

Опубликовано: 27 Март 2026
на канале: Keysight Hands-On
65,474
209

http://www.keysight.com/find/34411a A simple Visual Basic for Excel program is used to send a *IDN? And retrieve the response. In addition a subroutine and button is added to reset the instrument. A Keysight 34411A Digital Multimeter is used as it has USB, LAN and a GPIB interface. It is easy to switch instruments by using the VISA address. You can download the Agilent Connection Expert for free from the Agilent.com.

You can find additional details for the 34411A here: http://www.keysight.com/find/34411a

The IO libraries can be downloaded for free: http://www.keysight.com/find/iolib

The Excel spreadsheet can be downloaded from the Agilent Technical Forums: https://community.keysight.com/thread...

The VBA code is shown below:

Option Explicit
Dim ioMgr As VisaComLib.ResourceManager
Dim instrAny As VisaComLib.FormattedIO488
Dim instrQuery As String
Dim instrAddress As String

Public Sub Intialize_Click()

On Error GoTo ioError
instrAddress = Range("B4").Value
Set ioMgr = New VisaComLib.ResourceManager
Set instrAny = New VisaComLib.FormattedIO488
Set instrAny.IO = ioMgr.Open("DMM3")
Exit Sub

ioError: MsgBox "An IO error occured:" & vbCrLf & Err.Description
End Sub

Public Sub cmdSendIDN_Click()
On Error GoTo ioError
instrAny.WriteString ("*IDN?")
MsgBox "*IDN? has been sent to Instrument"
Exit Sub

ioError: MsgBox "An IO error occured:" & vbCrLf & Err.Description
End Sub

Public Sub cmdReadIDN_Click()
On Error GoTo ioError
instrQuery = instrAny.ReadString
MsgBox instrQuery, , "Instrument response to *IDN"
Exit Sub

ioError: MsgBox "An IO error occured:" & vbCrLf & Err.Description
End Sub

Public Sub instrclose_Click()

On Error GoTo ioError
instrAny.IO.Close
MsgBox "Connection Closed"
Exit Sub

ioError: MsgBox "An IO error occured:" & vbCrLf & Err.Description
End Sub