VBA: Serial I/O using kernel32

I

Ian Wade G3NRW

I am trying to get the following (well-known) code working under Excel
2003 and Windows XP:

<http://dev.emcelettronica.com/serial-port-communication-excel-vba>

This code is followed by:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Private Sub CommandButton1_Click()
Dim intPortID As Integer ' Ex. 1, 2, 3, 4 for COM1 - COM4
Dim lngStatus As Long

intPortID = 1

' Open COM port
lngStatus = CommOpen(intPortID, "COM" & CStr(intPortID), _
"baud=9600 parity=N data=8 stop=1")
End Sub
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Using a serial line analyzer, I see that nothing happens when pressing
CommandButton1. The COM port does not open.

Before I jump in to debug this in detail, a couple of questions:

1. Has anyone here got this code working successfully?

2. Do I have to declare kernel32 somewhere else before this code will
work?

(Before anyone asks, I am talking specifically about kernel32. I need to
use this for program portability, without the need for the user to
install anything else to make it work).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top