MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Can excel dial phone numbers?

Posted by Paul on August 23, 2001 7:04 AM

Is it possible to have a phone number in excel and when you click on it have excel dial that number? maybe by using phone dialer in windows. Thanks

Posted by Jerid on August 27, 2001 7:15 AM

Paul, here is some code I came across, I don't have an analog phone line at my desk so I couldn't test it 100%, but it seemed to work.

You need to set a reference to the Microsoft Comm Control 6.0 through Tools, References before it will work. You will have to play with the code to make it work for you.

I coded it so that it dials when I double click on a cell with the phone number.

-----START OF CODE-----
Dim CancelFlag As Integer

Private Sub cmdStop_Click()
CancelFlag = 1
End Sub

Private Sub Worksheet_Activate()
'Setting InputLen to 0 tells MSComm to read the entire contents of the
'input buffer when the Input property is used.

MSComm1.InputLen = 0
End Sub

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Excel.Range, Cancel As Boolean)
Dim Number As String

' Get the number to dial.
Number = Target.Value
If Number = "" Then Exit Sub

' Dial the selected phone number.
Dial (Number)

End Sub

Private Sub Dial(Number)
Dim DialString As String
Dim FromModem As String
Dim dummy As Integer

' AT is the Hayes compatible ATTENTION command and is required to send commands to the modem.
' DT means "Dial Tone." The Dial command uses touch tones, as opposed to pulse (DP = Dial Pulse).
' Numbers is the phone number being dialed.
' A semicolon tells the modem to return to command mode after dialing (important).
' A carriage return, vbCr, is required when sending commands to the modem.
DialString = "ATDT" + Number + ";" + vbCr

' Communications port settings.
' Assuming that a mouse is attached to COM1, CommPort is set to 2
MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"

' Open the communications port.
On Error Resume Next
MSComm1.PortOpen = True
If Err Then
MsgBox "COM1: not available. Change the CommPort property to another port."
Exit Sub
End If

' Flush the input buffer.
MSComm1.InBufferCount = 0

' Dial the number.
MSComm1.Output = DialString

' Wait for "OK" to come back from the modem.
dummy = DoEvents()
' If there is data in the buffer, then read it.
If MSComm1.InBufferCount Then
FromModem = FromModem + MSComm1.Input
' Check for "OK".
If InStr(FromModem, "OK") Then
' Notify the user to pick up the phone.
MsgBox "Please pick up the phone and either press Enter or click OK"
Exit Do
End If
End If

' Did the user choose Cancel?
If CancelFlag Then
CancelFlag = False
Exit Do
End If

' Disconnect the modem.
MSComm1.Output = "ATH" + vbCr

' Close the port.
MSComm1.PortOpen = False
End Sub
-----END OF CODE-----

Hope this helps.