Public Sub Dial(num As String)
On Error Resume Next
Dim Communications 'As MSCommLib.MSComm
Set Communications = CreateObject("MSCommLib.MSComm")
DialString$ = "ATDT" + num + ";" + Chr$(13)
Communications.CommPort = 3
Communications.Settings = "300,N,8,1"
On Error Resume Next
Communications.PortOpen = True
If Err Then
MsgBox Err.Description
' MsgBox "COM1: not available. Change the CommPort property to another port."
Exit Sub
End If
' Flush the input buffer.
Communications.InBufferCount = 0
' Dial the number.
Communications.Output = DialString$
' Wait for "OK" to come back from the modem.
Do
dummy = DoEvents()
' If there is data in the buffer, then read it.
If Communications.InBufferCount Then
FromModem$ = FromModem$ + Communications.Input
' Check for "OK".
If InStr(FromModem$, "OK") Then
' Notify the user to pick up the phone.
Beep
' MsgBox "Please pick up the phone and either press Enter or click OK"
Exit Do
End If
End If
Loop
' Disconnect the modem.
Communications.Output = "ATH" + Chr$(13)
' Close the port.
Communications.PortOpen = False
End Sub