views:

1276

answers:

2

What is the best way to access a serial port from VBA?

I have a need for some of our sales reps to be able to send a simple string over the serial port from an action button in PowerPoint. I don't commonly use VBA, especially for anything like this. Normally I would turn it into an application of some sort, but I actually don't think the idea is that bad. It will be a handy tool for them to demo this device with while on a projector and talking to other sales guys and non technical people. Also, this sales guy will have no problem making small modifications to the VBA or PowerPoint presentation, but would not do as well with recompiling a .NET application.

I know we could do it through a batch file run from the presentation on the action, but that doesn't make me very happy. I figure we could probably access a COM object and run from there, but again I am not real up on the latest and greatest libraries to use in VBA, and it would also be nice to get a quick little primer in how to easily open, send and close the connection.

Since this will need to be run on multiple people's computers, it would be nice if it would be easily transportable to other machines. I should be able to say it has to run on Office 2007 and Windows XP. Compatibility with anything else would be a nice bonus though.

How should I go about handling this? Any good tips or tricks? Library recommendations?

A: 

VISA supports serial I/O in addition to other I/O transports. The COM interface to VISA uses OLE-compatible custom (not dispatch-based) interfaces that are compatible with languages such as VBA that support early-binding with COM custom interfaces. The Agilent IO Libraries Suite has VISA COM support, examples and documentation. Check out http://www.agilent.com/find/iosuite to see if you have a license to download it.

David Gladfelter
+7  A: 

The Win32 API handles the serial port as a file. You can access the serial ports directly by calling these API functions from within VBA. I had to do this for an old .NET application but VBA is no different.

Rather than hash it out for you on this site, here's a reference I've hung onto over the years. How to perform serial port communications in VBA

Some Canuck
+1 For site having a working example.
Oorang