Hello friends,
I have found a very interesting tip for you.I know that many people store there contacts in excel file and where ever you wan to make a call, you need to open the file and dial the number.But guess if you can directly make a call when you open up your excel file for this thing to happen you need to use this code.
For that 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.
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.
Do
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.
Beep
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
Loop
' Disconnect the modem.
MSComm1.Output = "ATH" + vbCr
' Close the port.
MSComm1.PortOpen = False
End Sub
Bookmarks