근데.. 순환문이 아닌데 시간이 오래 걸린다는 것은.. 뭔가 코딩에 문제가 있어보이네요.. @_@;;
그리고.. 대분분의 작업에는 작업진행바가 필요없습니다. 순식간에 끝나버려서요.. @_@;;
Application.OnTime 등을 이용해서 예측된 시간에서 동작시키는 것은 오히려 더 신뢰도가 떨어질 것 같습니다.
컴퓨터 사양에 따라 처리 속도는 천차만별이기때문이죠..
'### 이하 코드~~~
'### 여러 프로세스로 구성된 작업 진행바 만들기 '### Created by http://abyul.com/ '### initial date : 2013.02.04 am 00:28 Dim frm As ufrmProgressBar Dim maxCount As Long Dim fullWidth As Long Dim lngProgress As Long
Sub abProgressBarShow() Set frm = New ufrmProgressBar frm.Label1.BackColor = 125 frm.Label1.Caption = "" maxCount = 3000 + ActiveWorkbook.Styles.Count + 200 + 2000 lngProgress = 0 fullWidth = frm.TextBox1.Width frm.Show End Sub
Sub abProgressBarMain() Call dummy1 Call dummy2 Call Macro1 Call dummy3 frm.Label1.Width = fullWidth frm.Label2.Caption = "작업 진행율 : " & Format(1, "0.0%") Set frm = Nothing End Sub
Sub dummy1() Dim sht As Worksheet: Set sht = Sheets.Add Dim rng As Range: Set rng = sht.Range("A1") For i = 1 To 3000 DoEvents rng.Offset(i).Value2 = i lngProgress = lngProgress + 1 frm.Label1.Width = fullWidth * (lngProgress / maxCount) frm.Label2.Caption = "작업 진행율 : " & Format(lngProgress / maxCount, "0.0%") If i = 1000 Then Debug.Print i End If Next i End Sub
Sub dummy2() Dim sht As Worksheet: Set sht = Sheets.Add Dim rng As Range: Set rng = sht.Range("A1") For i = 1 To sht.Parent.Styles.Count DoEvents rng.Offset(i).Value2 = sht.Parent.Styles(i).Name lngProgress = lngProgress + 1 frm.Label1.Width = fullWidth * (lngProgress / maxCount) frm.Label2.Caption = "작업 진행율 : " & Format(lngProgress / maxCount, "0.0%") Next i End Sub
Sub dummy3() Dim sht As Worksheet: Set sht = Sheets.Add Dim rng As Range: Set rng = sht.Range("A1") For i = 1 To 2000 DoEvents rng.Offset(i).Value2 = i lngProgress = lngProgress + 1 frm.Label1.Width = fullWidth * (lngProgress / maxCount) frm.Label2.Caption = "작업 진행율 : " & Format(lngProgress / maxCount, "0.0%") Next i End Sub
맑은이슬님.. 반갑습니다.
다른분에게 했던 답변을 참고하셨군요..
훈늉한 자세입니다. ^^)b
답변 하나 하나에 정성한 다한 보람이 있네요.. ^_^;;
첨부파일을 참고하시기 바랍니다.
다운받기 : abyul.com_progressBar_20130130-3.xlsm
대부분 작업이 오래 걸리는 작업은 순환문이기때문에..
For문이나 While문의 변수를 사용해서 진행바를 표시하면 될 것 같습니다.
그 외의 작업에는 가중치를 줘서 중간 중간에 한번씩 점프를 시켜야할 것 같네요..
이 프로세스 끝났으면 10%쯤 되겠다해서.. 10%로 점프를.. @_@;;
근데.. 순환문이 아닌데 시간이 오래 걸린다는 것은.. 뭔가 코딩에 문제가 있어보이네요.. @_@;;
그리고.. 대분분의 작업에는 작업진행바가 필요없습니다. 순식간에 끝나버려서요.. @_@;;
Application.OnTime 등을 이용해서 예측된 시간에서 동작시키는 것은 오히려 더 신뢰도가 떨어질 것 같습니다.
컴퓨터 사양에 따라 처리 속도는 천차만별이기때문이죠..
'### 이하 코드~~~
'### 여러 프로세스로 구성된 작업 진행바 만들기
'### Created by http://abyul.com/
'### initial date : 2013.02.04 am 00:28
Dim frm As ufrmProgressBar
Dim maxCount As Long
Dim fullWidth As Long
Dim lngProgress As Long
Sub abProgressBarShow()
Set frm = New ufrmProgressBar
frm.Label1.BackColor = 125
frm.Label1.Caption = ""
maxCount = 3000 + ActiveWorkbook.Styles.Count + 200 + 2000
lngProgress = 0
fullWidth = frm.TextBox1.Width
frm.Show
End Sub
Sub abProgressBarMain()
Call dummy1
Call dummy2
Call Macro1
Call dummy3
frm.Label1.Width = fullWidth
frm.Label2.Caption = "작업 진행율 : " & Format(1, "0.0%")
Set frm = Nothing
End Sub
Sub dummy1()
Dim sht As Worksheet: Set sht = Sheets.Add
Dim rng As Range: Set rng = sht.Range("A1")
For i = 1 To 3000
DoEvents
rng.Offset(i).Value2 = i
lngProgress = lngProgress + 1
frm.Label1.Width = fullWidth * (lngProgress / maxCount)
frm.Label2.Caption = "작업 진행율 : " & Format(lngProgress / maxCount, "0.0%")
If i = 1000 Then
Debug.Print i
End If
Next i
End Sub
Sub dummy2()
Dim sht As Worksheet: Set sht = Sheets.Add
Dim rng As Range: Set rng = sht.Range("A1")
For i = 1 To sht.Parent.Styles.Count
DoEvents
rng.Offset(i).Value2 = sht.Parent.Styles(i).Name
lngProgress = lngProgress + 1
frm.Label1.Width = fullWidth * (lngProgress / maxCount)
frm.Label2.Caption = "작업 진행율 : " & Format(lngProgress / maxCount, "0.0%")
Next i
End Sub
Sub dummy3()
Dim sht As Worksheet: Set sht = Sheets.Add
Dim rng As Range: Set rng = sht.Range("A1")
For i = 1 To 2000
DoEvents
rng.Offset(i).Value2 = i
lngProgress = lngProgress + 1
frm.Label1.Width = fullWidth * (lngProgress / maxCount)
frm.Label2.Caption = "작업 진행율 : " & Format(lngProgress / maxCount, "0.0%")
Next i
End Sub
Sub Macro1()
Sheets.Add
Range("B4:J33").Select
Selection.FormulaR1C1 = "=RAND()*100"
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
'### 코드 생략 ~~~
lngProgress = lngProgress + 100
frm.Label1.Width = fullWidth * (lngProgress / maxCount)
frm.Label2.Caption = "작업 진행율 : " & Format(lngProgress / maxCount, "0.0%")
'### 코드 생략 ~~~