Solved

access to com port from Excel VBA?

Posted on 1998-04-11
2
896 Views
Last Modified: 2011-10-03
Is it possible to read/write to COM port from VBA modul from Excel?
TWA.
Oleg Korsak
omk@iname.com
0
Comment
Question by:omk
  • 2
2 Comments
 
LVL 7

Expert Comment

by:kamall
ID: 1461044
If you have the MSCOMM control in the toolbox, you can access the COM port.
I can give you the VB code.
0
 
LVL 7

Accepted Solution

by:
kamall earned 100 total points
ID: 1461045
This is a sample code:
Put one COM control, 2 text boxes, and one commend button on your form, and enter this code in the command1_Click event:
(This code sends command to the modem and gets the reply. Run the project and enter the modem command in Text1 box and click the command button)

Private Sub Command1_Click()
Comm1.PortOpen = True
Text2.Text = "WAIT..."

    ' Flush the input buffer.
    Comm1.InBufferCount = 0
    Comm1.OutBufferCount = 0
    'Send command
    Comm1.Output = Text1.Text + Chr(13)
   
    ' Wait for 5 seconds for answer to come back from the modem.
    x = Timer
    Do
       dummy = DoEvents()
       ' If there is data in the buffer, then read it.
       If Comm1.InBufferCount Then
          FromModem$ = FromModem$ + Comm1.Input
       End If
    Loop Until Timer = x + 5
Text2.Text = FromModem$

Comm1.PortOpen = False
End Sub


0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now