2012-10-30 4 views
1

내 통합 문서의 모든 파일에서 작동하는 매크로이며 시트가 표시되어 있으면 의 매크로를 실행합니다. 나는 레이블이있는 사용자 정의 폼을 사용하는 것과 동일한 들어매크로를 실행하는 동안 진행률 표시 줄

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 

매크로가 백그라운드에서 실행될 때 진행률 표시 방법을 보여줄 수 있습니까?

답변

3

문제는 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 
+0

문제가 ** ** 제 UserForm1을 실행한다는 것이다. 진행률 막대가 가득 차면 루프가 시작됩니다. 나는 둘 다 동시에 일어나고 진행 바를 루프의 진행 상황을 보여주기를 원한다. – Cprog