Solved

access to com port from Excel VBA?

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

943 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

9 Experts available now in Live!

Get 1:1 Help Now