Usage of serial port in VBA ( exel )

A

Alexi Dobrev

I am trying to read and write data to COM1 based on an excel table, but
can't find a way to do it directly from VBA.

Any idea how to use mscomm32.ocx in VBA form?
 
T

Tom Ogilvy

Here is some information I have collected in the past. Never had a personal
need to use it:

http://www.yes-tele.com/mscomm.html
mscomm control


===================

posted by eric in programming 10/27/2003

In the VBE, create a userform. Next, create a
communications control (Microsoft Communications Control,
version x.x) and name it Comm1.

In the properties window of the communications control,
see what the name is. We'll name this one comExcel for the
examples below.

Then in a module, type:
Comm1.comExcel.CommPort = [Enter the com port here]

Comm1.comExcel.Settings = "9600,n,8,1" 'enter your own for
your device

Comm1.comExcel.PortOpen = True 'opens the port

Comm1.comExcel.Output = anything that needs to read from
the computer to the PC

Use at your own risk!!!! This code works for our weight
scales, but you'll have to read your manual to get the
output you desire. If anyone has any other suggestions,
please feel free.


----------------------------------
Thomas Lutz
Unfortunately Excel makes it almost impossible to do serial
communications directly using VBA.
Fortunately there are other easy solutions for inputting serial data
into Excel from devices like scales, measuring tools and bar code
readers.
The company that I work for sells a serial communications program
called the Software Wedge that you may find to be a good tool for
adding serial communications capabilities to your application. The
Software Wedge is an executable program that can pass serial data back
and forth to other programs using either DDE (Dynamic Data Exchange)
or by converting incoming serial data to keystrokes (i.e. it stuffs
the keyboard buffer with the incoming serial data).
The program is extremely easy to use and is designed to have you up
and running sending and receiving serial data directly from within
your application in just a few minutes.
Please visit http://www.taltech.com for more information.


This link has some free utilities from TalTech:

http://www.taltech.com/freesoftware/fs_sw.htm
------------------------------------

http://www.windmill.co.uk/faq.html

---------------------------------------
http://www.programurl.com/developer-tools-components-libraries-30.htm

================================================
Tim


Following was posted by Jack Silver as indicated: He was
speaking of reading
the comm port for information from instrumentation, but
the information
provided should be applicable.


Regards,
Tom Ogilvy


==================
From: "Jack Silver" <[email protected]>
Newsgroups: microsoft.public.excel.program­ming
Subject: Re: RS232 communication in excel
Date: Thu, 5 Oct 2000 19:32:17 -0400
Organization: Photon Technology International
Lines: 61
======================
There are a few ways to do this. If the instrument
provides data on its own
(such as a lab balance or bar code reader), you may
consider software wedge
(see http://www.taltech.com/). This reads the serial port,
and data is
entered into Excel as if it was entered into the keyboard
(in fact, it
pushes data into the keyboard buffer). This program has
the ability to parse
data (to separate the data from the data header), and
insert keystorkes
(notably the "enter key" so Excel moves to the next row
for the next data
point).


If you are using Excel '97 or Excel 2000, it can also be
done with an
ActiveX control added in and a little macro programming.
This solution is
better if the instrument needs to be controlled by
software. If you have
Visual Basic, professional edition or better, you can use
MSCOMM32.OCX. If
you don't have VB, you can purchase similar controls from
Programmer's
Paradise or Greenleaf Software (http://www.gleaf.com/,
now sysFire LLC?)


However, for simple communications, you can use a free
control downloaded
from the following site:
http://www.pti-can.com/public/Software/SID-101/
You will want to download cheapcomm.zip- this will contain
an installation
program (to install the control so Excel or Visual Basic
can access it),
documentation (as a Word file), and a help file that
describes the various
functions in the control.


The file VisualBasicLib.zip in the same location shows how
to use the
control in a VB or VBA program. An example program using
Excel to read/write
data to a GPS with COM1 can be found at:
http://ourworld.compuserve.com/homepages/jacksilver/softwar
e.htm (this uses
CheapComm)
A change in the program in a single line will cause it to
use COM2.


After installing the component (either Cheapcomm or
another component), you
will need to tell Excel you are using it. From the VBA
program (Excel 2000
menus described here, Excel 97 will be similar), use the
menu item "Insert",
then select "Components". All the ActiveX components
installed in your
computer will appear- Check the serial port component you
will use.
CheapComm and MSCOMM32.OCX can be placed on a dummy form
for use, and
accessed from the form. In Excel 2000, they can be
accessed by declaring
them as an object. Although the instructions for most of
these programs
refer to Visual Basic, the same instructions apply to VBA,
whether used in
Excel, Word, or Powerpoint.


Hope this helps.
 
R

relief

For only 35$ USD only with Bill Redirect software WWW.BILLPRODUCTION.COM
you can communicate with your peripheral (balance, bar code
reader...).

With this software you can read the serial port and data is entered
directly into Excel via a DDE CONNECTION

The Software BillRedirect is an executable program that can pass
serial data back and forth to other programs using either DDE (Dynamic
Data Exchange) or by converting incoming serial data to keystrokes.
The program is extremely easy to use and is designed to have you up
and running sending and receiving serial data directly from within
your application in just a few minutes. Please visit http://www.billproduction.com
for more information.

WinWedge Std: $259
WinWedge Pro: $495
BillRedirect (that make the same job !): 35$

* If you need a fonctionnality in BillRedirect ... Usualy it's Free if
you order a 3 copy !
* With BillRedirect the technical support is free !
 

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