0

我正在使用一个相当简单的脚本来自动拨打一组号码。它在我的计算机(带有集成调制解调器的笔记本电脑)上正常工作,但在我的同事计算机(脚本首先设计给他)上它适用于第一个数字,然后它根本不起作用(调制解调器赢了'不要拨打任何号码,也不会显示任何错误),除非我们重新启动计算机。什么设置或 mscomm 属性可以解释这种行为?我怀疑也许我在通话结束时关闭了扬声器,而不是在新通话开始时打开它......

    Dim CancelFlag As Integer
Dim RingCount As Integer
Dim raccrocherFlag As Integer

' Démarrage
Private Sub btnStart_Click()
' On Error GoTo Gest_err
    For Each numtel In Sheets("ListeTRS").Range("b2:b10000")
            ' Si bouton Cancel a été pressé, on arrête le script
            If CancelFlag = 1 Then
                UserForm1.Hide
                Exit Sub
            End If


            valNumtel = Val(numtel)
            If valNumtel = 0 Then
                MsgBox "Fin de fichier."
                Exit Sub
            Else
                ActiveSheet.Range("A" & numtel.Row).Select
                If Application.Wait(Now + TimeValue("0:00:2")) Then Dial numtel, numtel.Row
            End If
    Next
End Sub


Private Sub Dial(Number, Indice)
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.

' Concatene 0 avant le numéro
dialnumber = "0" & Number

DialString = "ATDT" + dialnumber + ";" + vbCr

' Communications port settings.
' A faire > detecter le port ou le demander à l'usager?
Dim comPort As Integer
comPort = 3
MSComm1.CommPort = comPort
MSComm1.Settings = "9600,N,8,1"
RingCount = 0

On Error Resume Next
    ' Ouvrir le port s'il est fermé
    If (MSComm1.PortOpen = False) Then
        MSComm1.PortOpen = True
    End If


    If Err Then
        MsgBox "COM" & comPort & " n'est pas disponible. Changer la propriété à un autre port."
        Exit Sub
    End If

' Flush the input buffer.
MSComm1.InBufferCount = 0

' Dial the number.
        Sheets("ListeTRS").Range("D" & Indice).Value = "Appel en cours du " & dialnumber & " § " & Now
        MSComm1.Output = DialString


         ' On attend 10 seconde puis on lis les infos disponible dans le tampon du modem
        If Application.Wait(Now + TimeValue("0:00:20")) Then
        FromModem = FromModem + MSComm1.Input
        End If


            ' Raccrocher
            MSComm1.Output = "ATH" + vbCr



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

' Close the port.
MSComm1.PortOpen = False
End Sub

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
4

1 回答 1

1

我自己也遇到过类似的情况。

您必须明确对象,在本例中为 Excel。假设您已将 xlApp 命名为 excel.aplication,请尝试以下操作:

For Each numtel In xlapp.Sheets("ListeTRS").Range("b2:b10000")

和:

If valNumtel = 0 Then
                MsgBox "Fin de fichier."
                Exit Sub
            Else
                xlApp.ActiveSheet.Range("A" & numtel.Row).Select
                If xlApp.Application.Wait(Now + TimeValue("0:00:2")) Then Dial numtel, numtel.Row
            End If
于 2014-10-26T11:13:14.460 回答