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

最佳答案

这已经困扰我一段时间了,你促使我寻找答案 - 谢谢。

实际上非常简单,只需将 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)

关于excel - 进度指示器,在vba中变得没有响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39915562/

相关文章:

Java XLS通过列名获取单元格

Excel 重新计算顺序 - 为什么从属单元格在前一个单元格之前计算?

vba - 在 vba excel 中使用 COUNTIF 的 DATE 条件的字符串值

vba - 如何为数据透视表动态选择数据范围

sql-server-2008 - 将 Access 应用程序连接到不同服务器中的 SQL Server 的可能方法?

c# - 我是否需要安装 Excel 才能使用 OleDB 提供程序查询电子表格?

vba - 将公式或值公式插入单元格时,Excel VBA 运行时错误 1004

mysql - 如何将Excel文件导入MySQL Workbench?

Excel VBA : How to remove substrings from a cell?

node.js - Node -exceljs : writing to file breaks fomulas in the file