进度指标,在vba中没有响应

时间:2016-10-07 10:56:23

标签: excel vba excel-vba

我一直在读 关于如何使用进度条的stackoverflow

它工作正常,但经过短时间6%后,我的235数组中的第14行表示没有响应,并且直到循环结束。

所以我正在运行vbmodeless:

ProgressBar.Show vbModeless

ProgressBar.Label_WhatsGoingOn.Caption = "Reading data from database.."

projectNumber = "32966"
docOutArray = Post.helpRequest("xdnjgjrdin.asp?Dok4=" & projectNumber)

If CPearson.IsArrayEmpty(docOutArray) Then
    MsgBox "No document registered in database!"
End If

ProgressBar.Label_WhatsGoingOn.Caption = "Creating Docout.."

Set doc_ = NEwDocOut.createDocOutDocument(projectNumber)

numOfRows = UBound(docOutArray, 1)


For i = LBound(docOutArray, 1) To numOfRows
    ProgressBar.Label_WhatsGoingOn.Caption = "Creating Row.."

    sPercentage = (i / numOfRows) * 100
    ProgressBar.progress (sPercentage)

我的进度条代码:

Private Sub UserForm_Initialize()
Me.Text.Caption = "0% Completed"
End Sub

Public Sub progress(pctCompl As Single)

Me.Text.Caption = Format(pctCompl, "##") & "% Completed"
Me.Bar.Width = pctCompl * 2
Me.Repaint
DoEvents

End Sub

为什么会发生这种情况?

enter image description here

3 个答案:

答案 0 :(得分:2)

这让我烦恼了一段时间,你促使我寻找答案 - 谢谢。

它实际上非常简单,只需将DoEvents放入循环中,在您的情况下:

For i = LBound(docOutArray, 1) To numOfRows
    'Add this line here:
    DoEvents

    ProgressBar.Label_WhatsGoingOn.Caption = "Creating Row.."

    sPercentage = (i / numOfRows) * 100
    ProgressBar.progress (sPercentage)

答案 1 :(得分:2)

这是我更新的代码建议:

render()

答案 2 :(得分:0)

尝试在标题的末尾添加空格-这样(无响应)将无法显示。

ProgressBar.Label_WhatsGoingOn.Caption =消息和空格(40)