我有ThisOutlookSession
每個郵件項目中的VBA腳本,並忽略代碼無關的部分,以我目前的問題,我打電話以下功能:函數總是返回False。爲什麼?
Function WriteBatFile(inVar As String) As Boolean
On Error GoTo err_handle:
Dim sFile As String
sFile = "C:\Users\ME\Desktop\myScript.bat"
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")
Dim oFile As Object
Set oFile = fso.CreateTextFile(sFile)
oFile.WriteLine "sleep 2"
oFile.WriteLine "./myScript.sh " & inVar
oFile.WriteLine "exit"
oFile.Close
Set fso = Nothing
Set oFile = Nothing
'MsgBox "Setting True", vbInformation
WriteBatFile = True
err_handle:
'MsgBox "Setting false. Code: "
WriteBatFile = False
Exit Function
End Function
我調用這個函數,並測試它是否返回True
或False
相應:
result = WriteBatFile(match.Value)
If result = True Then
retval = Shell("""C:\Program Files (x86)\PuTTY\plink.exe"" -ssh [email protected] -m C:\Users\ME\Desktop\runThese.bat", vbNormalFocus)
End If
然而,當功能被稱爲MsgBox
顯示它是設置True
但隨後其他MsgBox
示出的功能被設置False
。也許問題是行WriteBatFile = True
?
當然,Shell
命令從不運行。我希望你的幫助告訴我爲什麼?
謝謝。
沒有錯誤 - 他的代碼在錯誤處理程序之前從不退出函數。 – xxbbcc
@叔叔 - 垃圾 - 是的。 –