How to use Excel as Phone Dialer
Here we will use TAPI to make outbound calls. We can make use of TAPI easily with any VBA compliant application e.g. Microsoft Excel, Access etc. or Visual Basic.
It's really quite easy to add outbound dialing to any Excel spreadsheet. Since you only need one API call (tapiRequestMakeCall), you have very little code to deal with.All you need is a single declare statement to cover the API call and one subroutine to handle the details of gathering the phone number from the user and calling the API function.
Start Excel and/or open a new workbook. Since you'll be doing a bit of coding, be sure that the Visual Basic toolbar and the Forms toolbar are visible. If not, select View | Toolbars and then place a check mark next to Visual Basic and Forms.
The first thing you need to do is add the TAPI function declaration. To do this you must first add a code module to the project. Select Insert | Macro | Module from the main menu or click on the Insert Module icon in the Visual Basic toolbar. Once the module has been added to the project, rename the tab to VBA Code. Now insert the following code :
Listing 1.1
'
' declare assisted-tapi function
'
Declare Function tapiRequestMakeCall Lib "TAPI32.DLL" (ByVal lpszDestAddress As String, ByVal lpszAppName As String, ByVal lpszCalledParty As String, ByVal lpszComment As String) As Long
Now you need to add a small subroutine that will determine the cell selected by the user, locate the associated phone number and then place the call using the TAPI function declared in Listing 1.1. Listing 1.2 shows the code needed for this routine. Place this code in the same module that contains the API declare.
Listing 1.2
'
' call number in active cell
'
Sub CallBtn()
Dim x As Long ' for return
Dim cPhone As String
Dim cName As String
'
cName = ActiveCell
cPhone = ActiveCell.Offset(0, 1)
'
x = tapiRequestMakeCall(cPhone, "", cName, "")
'
End Sub
Now all you need to do is lay out the worksheet page to contain the name/phone number pairs. Use the Create Button icon from the Forms toolbar to add the button to the worksheet. When you are prompted to enter the macro associated with this button, be sure to enter the name of the subroutine shown in Listing 1.2 (CallBtn). It doesn't matter where you place things on the form. Just be sure to arrange the Name and Phone columns next to each other. The CallBtn subroutine will only work if the two columns are arranged side-by-side in the proper order.
Save the file as MyDialer.xls and then highlight a name and press the Call button. You should hear the modem in your pc dialing the number and see a dialog box on your screen.