Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 运行宏时的进度条_Excel_Vba - Fatal编程技术网

Excel 运行宏时的进度条

Excel 运行宏时的进度条,excel,vba,Excel,Vba,这是一个适用于我的工作簿的所有文件并执行宏wrap 如果图纸可见,则显示在所有图纸上。我想显示一个进度条,以便在宏运行时显示进度 Sub execute() Application.ScreenUpdating = False Application.Cursor = xlWait ' makes sure that the statusbar is visible Application.DisplayStatusBar = True 'add your message to status b

这是一个适用于我的工作簿的所有文件并执行宏wrap 如果图纸可见,则显示在所有图纸上。我想显示一个进度条,以便在宏运行时显示进度

Sub execute()
Application.ScreenUpdating = False
Application.Cursor = xlWait
' makes sure that the statusbar is visible
Application.DisplayStatusBar = True
'add your message to status bar
Application.StatusBar = "Formatting Report..."
userform1.show

    Call Delete_EmptySheets
    Dim WS_Count As Integer
    Dim i As Worksheet

 ' Set WS_Count equal to the number of worksheets in the active
 ' workbook.

 WS_Count = ActiveWorkbook.Worksheets.Count

' Begin the loop.

For Each i In Worksheets
If Not i.Visible = xlSheetVeryHidden Then
  i.Select
  Call wrap
End If
Next i

Application.Cursor = xlDefault
' gives control of the statusbar back to the programme
Application.StatusBar = False
Application.ScreenUpdating = True
End Sub
同样,我使用了一个带有标签的userform,但它只在宏execute

Private Sub UserForm_Activate()
 Call ShowProgressBarWithoutPercentage
End Sub

Sub ShowProgressBarWithoutPercentage()
Dim Percent As Integer
Dim PercentComplete As Single
Dim MaxRow, MaxCol As Integer
Dim iRow, iCol As Integer
MaxRow = 500
MaxCol = 500
Percent = 0
'Initially Set the width of the Label as Zero
UserForm1.Label1.Width = 0
For iRow = 1 To MaxRow
    For iCol = 1 To MaxCol
        Worksheets("Sheet1").Cells(iRow, iCol).Value = iRow * iCol

    Next
    PercentComplete = iRow / MaxRow
    UserForm1.Label1.Width = PercentComplete * UserForm1.Width

Next
Unload UserForm1
End Sub

当宏在后台运行时,是否有人可以显示显示progressbar的方法?

问题可能是您的
应用程序。ScreenUpdate=False
。您可以定期更新屏幕,但这可能会首先否定将其设置为
False
的好处。但是状态栏仍然会更新,因此您可以在状态栏中写入以下内容

0%  |
10% ||||||
并在宏运行时更新

25%  ||||||||||||||
...
50%  ||||||||||||||||||||||||||||
...
100% ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
下面是一个例子:

Sub StatusBarPercent(Percent As Double)
    Dim i As Long
    Dim Status As String
    Percent = Percent * 100
    Status = "Formatting Report...  " & Percent & "% "
    For i = 0 To Percent
        Status = Status & "|"
    Next
    Application.StatusBar = Status
End Sub
问题是第一个userform1执行。当进度条变满时,循环开始。我希望两者同时发生,并且进度条显示循环完成的进度。