我已经创建了一个GIF,当我运行搜索脚本时应该运行,但是它只在脚本结束时运行(它只是GIF的图片,直到脚本完成)。有办法让它一直运行吗?我已经尝试将GIF作为一个单独的UserForm,但是当脚本运行时它仍然冻结。我试过切换不同的开关(自动计算,启用事件,屏幕更新),我也试过改变“做事件”的位置,但我不能让GIF开始动画。
Public Sub SearchButton_Click()
WebBrowser1.Visible = True
WebBrowser1.Navigate "C:\Users\E100676\Pictures\loading.gif"
DoEvents
WebBrowser1.Document.body.Scroll = "no"
On Error Resume Next
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
DoEvents
Dim found As Range, totalcells As Long, B(), nr As Long, nc As Integer, i As Long, j As Integer
Dim Counter As Long, CurrentProgress As Double, ProgressPercentage As Double, BarWidth As Long
nr = WorksheetFunction.CountA(Range(Cells(3, 2), Cells(3, 2).End(xlDown))) + 2
nc = WorksheetFunction.CountA(Range(Cells(2, 2), Cells(2, 2).End(xlToRight))) + 1
ReDim B(3 To nr, 2 To nc)
'create array
For i = 3 To nr
For j = 2 To nc
B(i, j) = Cells(i, j)
Next
Next
'search
Counter = 0
If TextBox1 <> "" Then
For i = 3 To nr
For j = 2 To nc
On Error Resume Next
If InStr(1, B(i, j), CBK200UserForm.TextBox1, vbTextCompare) Then
If IsError(InStr(1, B(i, j), CBK200UserForm.TextBox1, vbTextCompare)) Then
Exit For
End If
Cells(i, 1).Resize(1, nc).Interior.Color = RGB(200, 255, 200)
Counter = Counter + 1
ESkip:
Exit For
End If
Next
Next
If Counter = 0 Then
MsgBox "No search results found.", vbExclamation, "Search Error"
GoTo Skipfilter
End If
If CBK200UserForm.Combo1.ListIndex = -1 Then
Cells(2, 2).AutoFilter field:=2
End If
Else
MsgBox "The search box is empty.", vbInformation, "Search Error"
GoTo Skipfilter
End If
Cells(2, 2).AutoFilter field:=2, Criteria1:=RGB(200, 255, 200), Operator:=xlFilterCellColor
Skipfilter:
WebBrowser1.Visible = False
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
End Sub
1条答案
按热度按时间xxls0lw81#
很有趣的想法,我喜欢它。若要在UNIX中运行脚本时显示动画GIF,可以通过将UserForm属性中的ShowModal属性更改为False来将UserForm设置为无模式。下面是一个示例代码:
它使用带有Show方法的vbModeless参数将UserForm1显示为无模式。这样就可以在不阻塞脚本执行的情况下显示UserForm。
您的脚本或代码逻辑在循环中运行。在本例中,它计数到2000,但您可以用实际的脚本替换它。脚本完成后,卸载UserForm。