0
我正在使用一個相當簡單的腳本來自動撥號一組數字。它可以在我的電腦(帶有集成調制解調器的筆記本電腦)上正常工作,但是在我的同事電腦上(首先爲其設計腳本),它適用於第一個號碼,然後它根本不工作(調制解調器獲勝撥打任何號碼,不顯示任何錯誤),除非我們重新啓動計算機。什麼設置或mscomm屬性可以解釋這種行爲?我猜想也許我關閉揚聲器在通話結束,不會在新的起點開啓...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
當你說「它不工作了」 - 沒有給出一個錯誤,或者確切地說怎麼了?你能在這裏粘貼腳本嗎?如果您希望我們能夠提供幫助,我們需要更多詳細信息! – Vicky 2013-04-23 08:41:15
當然,我已經添加了更多細節和腳本本身。有幾條評論是法文的,對不起。 – Chipsgoumerde 2013-04-23 08:53:54
你是否已經在同事的機器上使用調試器完成腳本? – Vicky 2013-04-23 09:00:58