|
求助各位老师,这两段代码怎样合并,谢谢
代码1:
Sub 计时()
If b = True Then
Application.OnTime Now + TimeValue("00:00:01"), "计时"
Sheet1.[l12] = Time
For i = 2 To 7
If Sheet1.[l12] < arr(2, x) Then
Sheet1.[l10] = ""
Sheet1.[l11] = arr(2, 1)
End If
If arr(i, x) = Sheet1.[l12] Then
Mp3name = ThisWorkbook.Path & "\" & arr(i, 1) & ".mp3"
MPlay (Mp3name)
Sheet1.[l10] = arr(i, 1)
If i < 7 Then
Sheet1.[l11] = arr(i + 1, 1)
Else
Sheet1.[l10] = ""
End If
t = arr(i, x) + TimeValue("00:02:10") '音乐播放20秒
End If
Next
If t = Time Then MStop (Mp3name)
End If
End Sub
代码2
Sub 计时开始()
Dim t1 As Date, t2 As Date
DoEvents
On Error Resume Next
With Sheets("时间表")
c = .Range("b1:g1").Find([l9]).Column
t1 = .Cells(5, c)
t2 = .Cells(7, c)
End With
With Sheets("操作表")
If Time <= t1 Then
.[j6].Font.Color = vbBlue
.[j6] = "距离考试开始时间还有"
.[j7] = t1 - Time
ElseIf Time <= t2 Then
.[j6].Font.Color = vbRed
.[j6] = "距离考试结束时间还有"
.[j7] = t2 - Time
Else
.[j6].Font.Color = vbBlack
.[j6] = "考试结束"
.[j7] = "00:00:00"
End If
.[l12].Value = Time
End With
Application.OnTime Time + TimeSerial(0, 0, 1), "计时开始"
End Sub
谢谢
试下这个代码吧,我是直接做了合并,我电脑上测试好像没出现这个问题,你再试一下下面的代码: - Sub 计时()
- Dim t1 As Date, t2 As Date
- On Error Resume Next
- If b = True Then
- Application.OnTime Now + TimeValue("00:00:01"), "计时"
- With Sheets("时间表")
- c = .Range("b1:g1").Find(Sheet1.[l9]).Column
- t1 = .Cells(5, c)
- t2 = .Cells(7, c)
- End With
- With Sheets("操作表")
- If Time <= t1 Then
- .[j6].Font.Color = vbBlue
- .[j6] = "距离考试开始时间还有"
- .[j7] = t1 - Time
- ElseIf Time <= t2 Then
- .[j6].Font.Color = vbRed
- .[j6] = "距离考试结束时间还有"
- .[j7] = t2 - Time
- Else
- .[j6].Font.Color = vbBlack
- .[j6] = "考试结束"
- .[j7] = "00:00:00"
- End If
- .[l12] = Time
- End With
- For i = 2 To 7
- If Sheet1.[l12] < arr(2, x) Then
- Sheet1.[L10] = ""
- Sheet1.[L11] = arr(2, 1)
- End If
- If arr(i, x) = Sheet1.[l12] Then
- Mp3name = ThisWorkbook.Path & "" & arr(i, 1) & ".mp3"
- MPlay (Mp3name)
- Sheet1.[L10] = arr(i, 1)
- If i < 7 Then
- Sheet1.[L11] = arr(i + 1, 1)
- Else
- Sheet1.[L10] = ""
- End If
- t = arr(i, x) + TimeValue("00:00:10") '音乐播放20秒
- End If
- Next
- If t = Time Then MStop (Mp3name)
- End If
- End Sub
复制代码
|
|