我有以下代碼運行良好的VBA。它調用另一個VBA Sub
沒有任何麻煩:計劃的VBA任務和'Application.OnTime'
Public Sub AutoPrintMissingHistoric()
Dim qdf As DAO.QueryDef
Dim rcs As DAO.Recordset
Dim db As DAO.Database
Dim j As Integer
Dim flag As Boolean
Dim i As Long
Dim value_start, value_end As String
Dim tmp As Date
Dim wbRiskedge As Workbook
Dim wsAccueil As Worksheet
Dim wsHistoric As Worksheet
Set wbRiskedge = Workbooks(StrWbRiskedge)
Set wsAccueil = wbRiskedge.Worksheets(StrWsAccueil)
Set wsHistoric = wbRiskedge.Worksheets(StrWsHistoricMissing)
If FistTime = True Then
Call Initialisation.CleanTab
Else
FistTime = True
Call Initialisation.Initialisation
End If
vDelay = 5
Cpt = Cpt + 1
Set db = DBEngine.OpenDatabase(strDB)
Set qdf = db.QueryDefs("Get_missing_fixings")
If Cpt <= wsAccueil.Range(ManualListLetter & "1").End(xlDown).Row Then
Application.StatusBar = wsAccueil.Cells(Cpt, ManualListLetter).Text
qdf.Parameters("arg1") = wsAccueil.Cells(Cpt, ManualListLetter).Value
Set rcs = qdf.OpenRecordset
j = 0
i = 1
flag = False
If Not rcs.EOF Then
rcs.MoveLast
rcs.MoveFirst
While Not rcs.EOF
j = 0
While j < rcs.Fields.Count
If flag = False Then
With Cells(i, j + 1)
If .Value = "" Then
.Value = rcs(j).Name
.Font.Bold = True
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
End If
End With
Else
Cells(i, j + 1).Value = rcs(j).Value
End If
j = j + 1
Wend
If flag = False Then
flag = True
End If
i = i + 1
rcs.MoveNext
Wend
Call ChangeMinMax(rcs.RecordCount, CellMinDate, CellMaxDate, wsHistoric)
Call ParseParameters
Call SetReutersFunction
End If
rcs.Close
qdf.Close
db.Close
wsHistoric.Calculate
Application.StatusBar = wsAccueil.Cells(Cpt, ManualListLetter).Text & " - Next Function: FindMissingValue.AutoFindMissingValue"
sToCall = "FindMissingValue.AutoFindMissingValue"
MTimeGT = Time + TimeValue("00:00:" & vDelay)
Application.OnTime MTimeGT, sToCall
End If
End Sub
我把這個過程的執行的計劃任務。但顯然我的代碼沒有很好的執行:FindMissingValue.AutoFindMissingValue
Sub沒有被調用,因爲Excel只是關閉了。
我認爲這是因爲Application.OnTime MTimeGT, sToCall
......可能是什麼原因?
在這裏,你已經中FindMissingValue.AutoFindMissingValue
Sub AutoFindMissingValue()
Dim wbRiskedge As Workbook
Dim wsAccueil As Worksheet
Dim wsHistoric As Worksheet
Dim i, nbResult As Long
Set wbRiskedge = Workbooks(StrWbRiskedge)
Set wsAccueil = wbRiskedge.Worksheets(StrWsAccueil)
Set wsHistoric = wbRiskedge.Worksheets(StrWsHistoricMissing)
If Left(wsHistoric.Range(ReutersFormula).Text, 13) Like "Retrieving...*" = True Then
sToCall = "FindMissingValue.AutoFindMissingValue"
MTimeGT = Time + TimeValue("00:00:05")
Application.OnTime MTimeGT, sToCall
Exit Sub
End If
i = WorksheetFunction.CountA(Columns(DateColumn & ":" & DateColumn))
If WorksheetFunction.CountA(Columns(ColumnResearchVResult & ":" & ColumnResearchVResult)) > 0 Then
wsHistoric.Range(FirstCellResearchVResult & ":" & ColumnResearchVResult & WorksheetFunction.CountA(Columns(ColumnResearchVResult & ":" & ColumnResearchVResult))).ClearContents
End If
nbResult = wsHistoric.Range(FirstResult).End(xlDown).Row
wsHistoric.Range(ColumnResearchVResult & LineResearchVResult - 1).Value = "Results"
If WorksheetFunction.CountA(Columns(DateColumn & ":" & DateColumn)) > 1 Then
wsHistoric.Range(FirstCellResearchVResult & ":" & ColumnResearchVResult & i).FormulaLocal = "=RECHERCHEV($" & DateColumn & "$" & LineResearchVResult & ":$" & DateColumn & "$" & i & ";" & FirstLockResult & ":$" & ValueResultColumn & "$" & nbResult & ";2;0)"
End If
Application.StatusBar = wsAccueil.Cells(Cpt, ManualListLetter).Text & " - Next Function: FindMissingValue.AutoPutResultInDb"
sToCall = "FindMissingValue.AutoPutResultInDb"
MTimeGT = Time + TimeValue("00:00:01")
Application.OnTime MTimeGT, sToCall
End Sub
你有沒有試過通過你的代碼調試? – 2013-08-16 09:21:29
調試不能處理計劃任務...所以我使用了'MsgBox'我在這個'Sub'中放了一個,在'Sub'中放了一個名爲'FindMissingValue.AutoFindMissingValue'。 ''FindMissingValue.AutoFindMissingValue'中的那個從不執行,而'Application.OnTime MTimeGT,sToCall'之前的執行。所以我認爲這是因爲'Application.OnTime',但我不知道如何解決它.... –