gpt4 book ai didi

excel - 运行宏时的进度条

转载 作者:行者123 更新时间:2023-12-04 22:09:04 24 4
gpt4 key购买 nike

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

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

同样,我使用了带有标签的用户表单,但它仅在宏 之前或之后执行执行
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

当宏在后台运行时,有人可以显示一种显示进度条的方法吗?

最佳答案

问题可能是您的 Application.ScreenUpdating = 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

关于excel - 运行宏时的进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13133684/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com