Option Explicit
Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
Sub DeleteJunkAndDeletedItems()
Dim flDeleted As Folder, flJunk As Folder, itDel As Object
Dim i As Long, iTotal As Long
Set flDeleted = Application.ActiveExplorer.Session.GetDefaultFolder(olFolderDeletedItems)
Set flJunk = Application.ActiveExplorer.Session.GetDefaultFolder(olFolderJunk)
iTotal = flJunk.Items.Count + flDeleted.Items.Count
ProgressBox.Show
ProgressBox.Increment 1, "Calculating..."
For Each itDel In flJunk.Items
i = i + 1
ProgressBox.Increment (i / iTotal) * 100, "Deleting 'Junk'..."
itDel.Delete
Next itDel
For Each itDel In flDeleted.Items
i = i + 1
ProgressBox.Increment (i / iTotal) * 100, "Deleting 'Deleted'..."
itDel.Delete
Next itDel
ProgressBox.Increment 100, "Complete!"
Sleep 250
ProgressBox.Hide
End Sub
Option Explicit
Private Const DefaultTitle = "Progress"
Private myText As String
Private myPercent As Single
Public Property Let Text(newText As String)
If newText <> myText Then
myText = newText
Me.Controls("UserText").Caption = myText
Call sizeToFit
End If
End Property
Public Property Get Text() As String
Text = myText
End Property
Public Property Let Percent(newPercent As Single)
If newPercent <> myPercent Then
myPercent = Min(Max(newPercent, 0#), 100#)
Call updateProgress
End If
End Property
Public Property Get Percent() As Single
Percent = myPercent
End Property
Public Sub Increment(ByVal newPercent As Single, Optional ByVal newText As String)
Me.Percent = newPercent
If newText <> "" Then Me.Text = newText
Call updateTitle
Me.Repaint
End Sub
Private Sub UserForm_Initialize()
Call setupControls
Call updateTitle
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then End
End Sub
Private Sub setupControls()
Dim i As Integer
Dim aControl As Label
For i = Me.Controls.Count To 1 Step -1
Me.Controls(i).Remove
Next i
Set aControl = Me.Controls.Add("Forms.Label.1", "UserText", True)
aControl.Caption = ""
aControl.AutoSize = True
aControl.WordWrap = True
aControl.Font.Size = 8
Set aControl = Me.Controls.Add("Forms.Label.1", "ProgressFrame", True)
aControl.Caption = ""
aControl.Height = 16
aControl.SpecialEffect = fmSpecialEffectSunken
Set aControl = Me.Controls.Add("Forms.Label.1", "ProgressBar", True)
aControl.Caption = ""
aControl.Height = 14
aControl.BackStyle = fmBackStyleOpaque
aControl.BackColor = &HFF0000
Call sizeToFit
End Sub
Private Sub sizeToFit()
Me.Width = 240
Me.Controls("UserText").Top = 6
Me.Controls("UserText").Left = 6
Me.Controls("UserText").AutoSize = False
Me.Controls("UserText").Font.Size = 8
Me.Controls("UserText").Width = Me.InsideWidth - 12
Me.Controls("UserText").AutoSize = True
Me.Controls("ProgressFrame").Top = Int(Me.Controls("UserText").Top + Me.Controls("UserText").Height) + 6
Me.Controls("ProgressFrame").Left = 6
Me.Controls("ProgressFrame").Width = Me.InsideWidth - 12
Me.Controls("ProgressBar").Top = Me.Controls("ProgressFrame").Top + 1
Me.Controls("ProgressBar").Left = Me.Controls("ProgressFrame").Left + 1
Call updateProgress
Me.Height = Me.Controls("ProgressFrame").Top + Me.Controls("ProgressFrame").Height + 6 + (Me.Height - Me.InsideHeight)
End Sub
Private Sub updateTitle()
If (Int(myPercent) Mod 5) = 0 Then
Me.Caption = DefaultTitle & " - " & Format(Int(myPercent), "0") & "% Complete"
End If
End Sub
Private Sub updateProgress()
If myPercent = 0 Then
Me.Controls("ProgressBar").Visible = False
Else
Me.Controls("ProgressBar").Visible = True
Me.Controls("ProgressBar").Width = Int((Me.Controls("ProgressFrame").Width - 2) * myPercent / 100)
End If
End Sub
Function Min(number1 As Single, number2 As Single) As Single
If number1 < number2 Then Min = number1 Else Min = number2
End Function
Function Max(number1 As Single, number2 As Single) As Single
If number1 > number2 Then Max = number1 Else Max = number2
End Function
|