phone dialer

sykes

Well-known Member
Joined
May 1, 2002
Messages
1,885
Office Version
  1. 365
Platform
  1. Windows
Hi Folks

I'm trying to use an Excel workbook to dial phone numbers in it's database.

I'm using this successfully:
Code:
Declare Function tapiRequestMakeCall Lib "TAPI32.DLL" (ByVal lpszDestAddress As String, ByVal lpszAppName As String, ByVal lpszCalledParty As String, ByVal lpszComment As String) As Long

Sub CallBtn()
Dim x As Long
Dim cPhone As String
cPhone = "01234 56789"
x = tapiRequestMakeCall(cPhone, "", "", "")
End Sub
...however, I don't want to start up, or even use, phone dialer if poss.
What I'm trying to do is talk directly to my modem (on COM3) and just get it to dial out. Perhaps I need to shell phone dialer, or hyperterminal? I don't know enough about it to know how to achieve this.
I found this on the board:
Code:
Sub dials()
PhoneNumber$ = "01234 56789"
Open "COM3:" For Output As #1
Print #1, "ATDT" & "01234 56789" & Chr(13)
Close #1
End Sub
...which looked hopeful, with the ATDT command for the modem, but all I hear is a click on the line when I run the code.
Any ideas? All thoughts greatly appreciated.
 
Try this :-
Code:
'====================================================================================================
'- DIAL A TELEPHONE NUMBER VIA MODEM
'- Brian Baulsom November 2007
'====================================================================================================
Option Explicit
Dim MSComm1 As Object
Dim MyNumber As String
Dim DialString As String

'====================================================================================================
'- MAIN ROUTINE
'====================================================================================================
Sub TEST()
    '- Telephone number
    MyNumber = "123"        ' UK talking clock
    DIAL MyNumber
End Sub
'---------- END OF MAIN ROUTINE ------------------------------------------------------------------

'====================================================================================================
'- SUBROUTINE : DIAL THE NUMBER
'====================================================================================================
Private Sub DIAL(Num As String)
    Dim DialString As String
    Dim FromModemString As String
    Dim rsp
    '------------------------------------------------------------------------------------------------
    '- COM3 setup
    Set MSComm1 = CreateObject("MSCommLib.MSComm")
    MSComm1.CommPort = 3            ' CHANGE IF REQUIRED
    MSComm1.Settings = "9600,N,8,1"
    '------------------------------------------------------------------------------------------------
    '- TEST COM LINK
    On Error Resume Next
    MSComm1.PortOpen = True
    If Err.Number <> 0 Then
       MsgBox "(COM3 not available)"
       Exit Sub
    End If
    On Error GoTo 0
    '------------------------------------------------------------------------------------------------
    '- DIAL NUMBER
    DialString = "ATDT" + Num + ";" + vbCr
    MSComm1.Output = DialString
    '------------------------------------------------------------------------------------------------
    '- WAIT FOR MODEM RESPONSE
    Do
        DoEvents
        If MSComm1.InBufferCount Then
            FromModemString = FromModemString + MSComm1.Input
            '------------------------------------------------------------------------------------------------
            ' Check for "OK". Prompt user to pick up phone
            If InStr(FromModemString, "OK") Then
                rsp = MsgBox("OK to get call or Cancel", vbOKCancel)
                If rsp = vbCancel Then Exit Do
            End If
        End If
    Loop
    '------------------------------------------------------------------------------------------------
    '- FINISH. DISCONNECT MODEM
    MSComm1.Output = "ATH" + vbCr
    MSComm1.PortOpen = False
End Sub
'===================================================================================================
 
Upvote 0
Hi Brian

Thanks very much for your reply.
I've tried your code, but am getting an error on this line:
Code:
Set MSComm1 = CreateObject("MSCommLib.MSComm")
this is the error:
run time error 429
Active X component can't create object.
I thought it may be caused by a missing reference, and had a butchers at the references in VBA, but none are showing up as missing.
Any further ideas?
Thanks again for your efforts........
 
Upvote 0
Thought you might. :)
===========================================================
INSTALLING, REGISTERING, and LICENCING AN .OCX CONTROL FOR VISUAL BASIC AND/OR VBA
EXAMPLE : "Microsoft Communications Control, version 6" MSCOMM32.OCX
Similar sometimes required for .DLL etc. used as code libraries
'============================================================

I have 2 machines running side by side and got the same result on one of them. This in itself is wierd because they are pretty much the same in content. I really do not know how the working version got there.

We need to install the required .OCX control. This requires quite a lengthy process. Because I have not found any single source that shows all the stages I have put a title in an attempt to help others find this message. This is quite a common requirement if you write any code. You may not need to do everything here in every case to get one to work. Some downloadable controls - and those included in other applications - include a process to all this automatically.

You will see below that I am helped by having Visual Basic 6 installed on my computer. Although this does nothing itself, the Microsoft Licencing procedure is made extremely easy.

**If you do not have VB6 and finally get it working it may help others if you add a message to show how you achieve it.**

NB. Expect to get error messages until the control or whatever is fully working at the end.

1. SEARCH FOR, AND DOWNLOAD THE REQUIRED FILE IF NECESSARY
in this case MSCOMM32.OCX (I had this on my other machine already. It might already be on your machine)

2. PUT THE FILE INTO THE FOLDER CONTAINING OTHER .OCX FILES
In Windows XP this seems to be C:\WINDOWS\SYSTEM32. This enables the file to be found automatically by the VB Editor (and others).

3. CHECK VB EDITOR DIALOG "Available References"
via "Tools/References". If you do this, and click on the references there, you will see what common folder to use at the bottom of the dialog ... "Location".

A big problem here is that the names given do not necessarily match with the file name - so we have to check quite a long list. At least MS names usually have "Microsoft" at the beginning.

While there ... note that it is possible to add references by using the Browse button. Might as well check the box against the file name if it is there. This registers controls with the VB Editor for the current project, and enables automation to get Help with the Properties & Methods as for other controls. If you distribute your VBA project your users may need to do all this too.

4. IF A CONTROL - CHECK CONTROLS TOOLBOX VIA VB EDITOR USERFORM
Often we are dealing with ActiveX controls with this method. They require manual addition to the Toolbox. Add a blank Userform to be able to get the controls Toolbox. Right click the toolbox, then 'Additional Controls'.

In this case you are looking for "Microsoft Communications Control, version 6". If found, check its box. Click OK. A new tool appears in the Toolbox. Can now try to put the control on to the Userform. Click & Drag. Error messages here means that it is not correctly installed .. keep going ..

Note : At this stage it is interesting to note that we do not really need to do this bit unless we want to use the control in a form. This is a good example. IF WE KNOW WHAT CODE TO USE WE DO NOT NEED THE USERFORM TOOL. If added to a form, this particular tool does not actually do anything. In fact we would probably want to hide it. However, it does give direct access to the Properties, which can then be set up without using code. This may be the only way to see all the properties. Documentation for such controls is really bad - even if you can find it.

5. REGISTER THE CONTROL
This makes a reference to the file in the registry.
Click Windows Start button, then Run. By whatever method you use (there is a Browse button) you need to get this - or similar into the "Open" box and click OK. :-

REGSERVR32 C:\WINDOWS\SYSTEM32\MSCOMM32.OCX

You should get a message to say the process was successful. If not, I do not know what to do other than try another version of the file. If you had errors above you can now go back to a previous stage and try again. Fiddling with all this can upset the system a bit, so I would reboot and try again.

6. LICENCE THE CONTROL USING VBUSC.EXE
VBUSC.EXE is a file that installs the Design-Time Licenses for ActiveX controls that shipped with earlier versions of Visual Basic, but are no longer supported and have been discontinued with the current version.

http://support.microsoft.com/default.aspx?scid=kb;en-us;Q195353

It seems that everything nowadays requires a licence. If this is the case here, by now the error message above is more exact. Having Visual Basic 6 installed, all I had to do was download this free file from Microsoft and run it. Nothing seemed to happen, but after running it the control worked. I was able to insert it into a Userform and run the code without error. I know it checks for a VB installation. I do not know what would happen without it.

Hope all this helps.
 
Upvote 0
Hi Brian
Thanks very much for putting so much effort into helping!
Before I actually got to see your latest post, I'd begun to investigate hyperterminal. I've wanted to try this for a while, and decided to have a bash.
This was actually a bonus because I've not used SendKeys before either, so it's been a great learning opportunity.
My code calls my phone_dialer function, which shells hyperterminal, passes the phone number to it, as a string, then gives it time to dial (and the user time to pick up the phone line), before finally disconnecting hyperterminal, and closing it down.
I'm posting the code here, in case anyone else wishes to do the same as I have.
Code:
Function phone_dialer(phone_number As String)
Shell ("C:\Program Files\Windows NT\hypertrm.exe"), 0
SendKeys "%{F4}"
SendKeys "ATDT" & phone_number & "~", True
Application.Wait (Now() + TimeValue("00:00:10"))
SendKeys "%CD", True
'Application.Wait (Now() + TimeValue("00:00:4"))
SendKeys "%{F4}", True
End Function
If anyone does wish to use it, then the file path may, of course, need to be changed, the "Wait" time values for different modems may need changing, and for interest's sake, if the user wishes to see the application in progress, change the 0 at the end of the first line to a 1 thus:
Code:
Shell ("C:\Program Files\Windows NT\hypertrm.exe"), 1

There are 2 things which you may be able to comment on Brian:
1. So far, Hyperterminal always opens with a "New Connection" window, (which is quite annoying, as we're not wishing to save a new connection), hence the second line in my code:
Code:
SendKeys "%{F4}"
....which is to close this window. The trouble is, even with the application hidden, this window still flashes up on the screen momentarily before the code closes it, and I'd like to overcome this to make it a little neater.
2. Using the SendKeys command
(at least I think it's that one that's doing it) sometimes (but not every time) puts the keyboard number lock off, which is also very annoying, as my programme deals mostly with data entry!

Any thoughts gratefully received.

You'll be pleased to know that I'm still going to investigate your MSCOMM32.OCX idea, as once it's in place, I think it'll perhaps be a better long term telephony solution, but as my present programme's for some friends who've got their own machines, and will undoubtedly want to run it on other machines as well, I need to use something which is readily available to all Windows OS PCs, and I think hyperterminal probably is. Mind you - that having been said, one of the machines is a Vista machine, so I'm now going to get on the phone to see if this one even HAS Hyperterminal on it - OR an internal modem!.........There's always something else isn't there?!!

Thanks again for your efforts to-date.

All the best
 
Upvote 0
I do not have anything to add. Tried Hyperterminal but no real experience, having found a suitable solution.

I guess it depends on your pain threshold. :-D
 
Upvote 0
Thought you might. :)
===========================================================
INSTALLING, REGISTERING, and LICENCING AN .OCX CONTROL FOR VISUAL BASIC AND/OR VBA
EXAMPLE : "Microsoft Communications Control, version 6" MSCOMM32.OCX
Similar sometimes required for .DLL etc. used as code libraries
'============================================================

I have 2 machines running side by side and got the same result on one of them. This in itself is wierd because they are pretty much the same in content. I really do not know how the working version got there.

We need to install the required .OCX control. This requires quite a lengthy process. Because I have not found any single source that shows all the stages I have put a title in an attempt to help others find this message. This is quite a common requirement if you write any code. You may not need to do everything here in every case to get one to work. Some downloadable controls - and those included in other applications - include a process to all this automatically.

You will see below that I am helped by having Visual Basic 6 installed on my computer. Although this does nothing itself, the Microsoft Licencing procedure is made extremely easy.

**If you do not have VB6 and finally get it working it may help others if you add a message to show how you achieve it.**

NB. Expect to get error messages until the control or whatever is fully working at the end.

1. SEARCH FOR, AND DOWNLOAD THE REQUIRED FILE IF NECESSARY
in this case MSCOMM32.OCX (I had this on my other machine already. It might already be on your machine)

2. PUT THE FILE INTO THE FOLDER CONTAINING OTHER .OCX FILES
In Windows XP this seems to be C:\WINDOWS\SYSTEM32. This enables the file to be found automatically by the VB Editor (and others).

3. CHECK VB EDITOR DIALOG "Available References"
via "Tools/References". If you do this, and click on the references there, you will see what common folder to use at the bottom of the dialog ... "Location".

A big problem here is that the names given do not necessarily match with the file name - so we have to check quite a long list. At least MS names usually have "Microsoft" at the beginning.

While there ... note that it is possible to add references by using the Browse button. Might as well check the box against the file name if it is there. This registers controls with the VB Editor for the current project, and enables automation to get Help with the Properties & Methods as for other controls. If you distribute your VBA project your users may need to do all this too.

4. IF A CONTROL - CHECK CONTROLS TOOLBOX VIA VB EDITOR USERFORM
Often we are dealing with ActiveX controls with this method. They require manual addition to the Toolbox. Add a blank Userform to be able to get the controls Toolbox. Right click the toolbox, then 'Additional Controls'.

In this case you are looking for "Microsoft Communications Control, version 6". If found, check its box. Click OK. A new tool appears in the Toolbox. Can now try to put the control on to the Userform. Click & Drag. Error messages here means that it is not correctly installed .. keep going ..

Note : At this stage it is interesting to note that we do not really need to do this bit unless we want to use the control in a form. This is a good example. IF WE KNOW WHAT CODE TO USE WE DO NOT NEED THE USERFORM TOOL. If added to a form, this particular tool does not actually do anything. In fact we would probably want to hide it. However, it does give direct access to the Properties, which can then be set up without using code. This may be the only way to see all the properties. Documentation for such controls is really bad - even if you can find it.

5. REGISTER THE CONTROL
This makes a reference to the file in the registry.
Click Windows Start button, then Run. By whatever method you use (there is a Browse button) you need to get this - or similar into the "Open" box and click OK. :-

REGSERVR32 C:\WINDOWS\SYSTEM32\MSCOMM32.OCX

You should get a message to say the process was successful. If not, I do not know what to do other than try another version of the file. If you had errors above you can now go back to a previous stage and try again. Fiddling with all this can upset the system a bit, so I would reboot and try again.

6. LICENCE THE CONTROL USING VBUSC.EXE


http://support.microsoft.com/default.aspx?scid=kb;en-us;Q195353

It seems that everything nowadays requires a licence. If this is the case here, by now the error message above is more exact. Having Visual Basic 6 installed, all I had to do was download this free file from Microsoft and run it. Nothing seemed to happen, but after running it the control worked. I was able to insert it into a Userform and run the code without error. I know it checks for a VB installation. I do not know what would happen without it.

Hope all this helps.

Brian,

I have sent out detailed instructions to my users about how to install Calendar Control 11.0 to their systems 32 folder and to then add it to the windows registry on their machines. I don't understand it how it is then that the calendar expected to arrive on the form when it is opened, doesn't appear. do you have any suggestions?
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top