Phoning With Outlook from Excel

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

Phoning With Outlook from Excel

Post by Don Wells »

Is it possible to pass a phone number from Excel to Outlook and have Outlook dial the number? I find VBA in Outlook to be inscrutable. :help:
Regards
Don

User avatar
HansV
Administrator
Posts: 78489
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Phoning With Outlook from Excel

Post by HansV »

I agree that Outlook VBA is not intuititve, but be glad you're not automating PowerPoint! Compared to PowerPoint VBA, Outlook VBA is a breeze... :grin:

However, the Dial method in Outlook VBA only accepts an Outlook contact, not an arbitrary phone number. I tried the SendKeys method to pass a phone number from Excel to the New Call dialog, but SendKeys confirmed its reputation of being flaky - it didn't work.

Try this code from Andy Pope. Insert the following code at the top of a standard module:

Code: Select all

Declare Function tapiRequestMakeCall Lib "tapi32.dll" _
    (ByVal stNumber As String, ByVal stDummy1 As String, _
     ByVal stDummy2 As String, ByVal stDummy3 As String) As Long

Sub DialNumber(Number As String)
     Dim lngStatus As Long
    ' Send the telephone number to the modem.
     lngStatus = tapiRequestMakeCall(Number, "", "", "")
     If lngStatus < 0 Then
         MsgBox "Failed to dial number " & Number, vbExclamation
     End If
 End Sub
You could call it like this in a macro:

Code: Select all

    Call DialNumber(Range("A1").Value)
or in the Worksheet_BeforeDoubleClick event procedure of a worksheet:

Code: Select all

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    If Not Intersect(Range("A2:A10"), Target) Is Nothing Then
        Call DialNumber(Target.Value)
        Cancel = True
    End If
End Sub
I don't have a phone modem in my PC, so I couldn't test it, but a connect dialog did appear, so hopefully it will work.
Best wishes,
Hans

User avatar
StuartR
Administrator
Posts: 12606
Joined: 16 Jan 2010, 15:49
Location: London, Europe

Re: Phoning With Outlook from Excel

Post by StuartR »

Hans,

I just tested this code with Excel 2010 on Windows 7 and it worked fine.
StuartR


User avatar
HansV
Administrator
Posts: 78489
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Phoning With Outlook from Excel

Post by HansV »

Thanks for testing it, Stuart! :thumbup:
Best wishes,
Hans

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

Re: Phoning With Outlook from Excel

Post by Don Wells »

Thank you Hans
    It works a treat on my 2003 installation. :thankyou:

    I'm too embarrassed to explain why it took me so long to reply. (RTFM) :blush:
Regards
Don

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

Re: Phoning With Outlook from Excel

Post by Don Wells »

    Having successfully dialed a number, is it possible to close the Phone Dialer using VBA code?
Regards
Don

User avatar
HansV
Administrator
Posts: 78489
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Phoning With Outlook from Excel

Post by HansV »

Undoubtedly, but I don't know how to do that, sorry.
Best wishes,
Hans

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

Re: Phoning With Outlook from Excel

Post by Don Wells »

Thank you Hans.
Regards
Don

User avatar
BobH
UraniumLounger
Posts: 9284
Joined: 13 Feb 2010, 01:27
Location: Deep in the Heart of Texas

Re: Phoning With Outlook from Excel

Post by BobH »

But, but . . . but . . .

What if you use cable modem? How do you dial from your computer then? :evilgrin
Bob's yer Uncle
(1/2)(1+√5)
Dell Intel Core i5 Laptop, 3570K,1.60 GHz, 8 GB RAM, Windows 11 64-bit, LibreOffice,and other bits and bobs

User avatar
Don Wells
5StarLounger
Posts: 689
Joined: 27 Jan 2010, 16:45
Location: Ottawa, Ontario, Canada

Re: Phoning With Outlook from Excel

Post by Don Wells »

HansV wrote:Undoubtedly, but I don't know how to do that, sorry.
Perhaps we are becoming too accustomed to Hans having and sharing knowledge that is unfathomably deep to mere mortals.
Again; :thankyou: Hans. :thankyou:
Regards
Don

User avatar
HansV
Administrator
Posts: 78489
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Phoning With Outlook from Excel

Post by HansV »

I actually don't know all that much, but I'm good at Googling. In this case, however, I only found very complicated code of which the authors complained that it didn't work consistently, so I didn't bother posting the code or a link to it here...
Best wishes,
Hans