Solved

access to com port from Excel VBA?

Posted on 1998-04-11
2
915 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Concatenate 2 userform comboboxes to a userform text box 4 65
Windows 10 start screen issues 9 55
Adding to a VBA? 6 71
VB 6 error 5 in windows 10 but not in XP 7 57
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

832 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