파일사이즈와 파일명을 오름차순, 내림차순으로 정렬할 수 있습니다.
'FileSize.pptm
'Search PPT files in the target folder and show each file's size with a bar-type graph
'by konahn(at)naver.com
Option Explicit
Option Base 1
Public Type FileType
FileName As String ' 파일명과 파일크기를 가진 새 타입 선언
FileSize As Long
End Type
Public Target As String
Public FileList() As FileType ' 파일목록 배열
Public MaxSize As Long ' 폴더내 가장 큰 파일사이즈
Public Started As Boolean ' 슬라이드 시작 표시
Public SortBy As Integer ' 정렬 옵션 0 unsort, 1 sort up by filename, -1 sort down by filename, 2/-2 sort up/down by filesize
Const Margin = 50 ' 슬라이드 여백
Const TopMargin = 75 ' 화면 여백
Const Height = 25 ' 막대 등의 높이
'시작
Sub Start()
CheckSortOption ' 정렬 옵션 체크
EraseAll ' 기존 슬라이드와 개체 모두 지우기
Target = GetFolder ' 폴더를 선택
ScanDir ' 파일 검색
If SortBy <> 0 Then SortFileList
DrawGraph ' 막대그래프 그리기
End Sub
Sub SortNow()
If UBound(FileList) < 1 Then
MsgBox "먼저 폴더를 선택하세요", vbCritical
Exit Sub
End If
ActivePresentation.SlideShowWindow.View.GotoSlide 1
CheckSortOption
EraseAll
If SortBy = 0 Then ScanDir Else SortFileList
DrawGraph
End Sub
Sub SortFileList()
Dim i As Integer, j As Integer
For i = 1 To UBound(FileList) - 1
For j = i + 1 To UBound(FileList)
Select Case SortBy
Case 1
If FileList(i).FileName > FileList(j).FileName Then Call SwitchList(i, j)
Case -1
If FileList(i).FileName < FileList(j).FileName Then Call SwitchList(i, j)
Case 2
If FileList(i).FileSize > FileList(j).FileSize Then Call SwitchList(i, j)
Case -2
If FileList(i).FileSize < FileList(j).FileSize Then Call SwitchList(i, j)
Case Else
End Select
Next j
Next i
End Sub
Sub SwitchList(a As Integer, b As Integer)
Dim temp As FileType
temp = FileList(a)
FileList(a) = FileList(b)
FileList(b) = temp
End Sub
'정렬 옵션에 따라 화면에 체크 표시
Sub CheckSortOption()
Dim i As Integer
If SortBy < -2 Or SortBy > 2 Then SortBy = 0
With ActivePresentation.Slides(ActivePresentation.SlideShowWindow.View.CurrentShowPosition)
For i = 0 To 2
If i = Abs(SortBy) Then .Shapes("Dir_SortBy" & i).GroupItems("Circle").Fill.ForeColor.RGB = rgbDodgerBlue _
Else .Shapes("Dir_SortBy" & i).GroupItems("Circle").Fill.ForeColor.RGB = rgbWhite
Next i
If SortBy = 0 Then
.Shapes("Dir_SortUp").GroupItems("Circle").Fill.ForeColor.RGB = rgbWhite
.Shapes("Dir_SortDown").GroupItems("Circle").Fill.ForeColor.RGB = rgbWhite
ElseIf SortBy > 0 Then
.Shapes("Dir_SortUp").GroupItems("Circle").Fill.ForeColor.RGB = rgbDodgerBlue
.Shapes("Dir_SortDown").GroupItems("Circle").Fill.ForeColor.RGB = rgbWhite
ElseIf SortBy < 0 Then
.Shapes("Dir_SortUp").GroupItems("Circle").Fill.ForeColor.RGB = rgbWhite
.Shapes("Dir_SortDown").GroupItems("Circle").Fill.ForeColor.RGB = rgbDodgerBlue
End If
End With
End Sub
'클릭시 정렬옵션 변경
Sub ClickOption(shp As Shape)
'MsgBox shp.ParentGroup.Name
If Left(shp.ParentGroup.Name, 10) = "Dir_SortBy" Then
SortBy = CInt(Mid(shp.ParentGroup.Name, 11)) ' 0, 1, 2
ElseIf shp.ParentGroup.Name = "Dir_SortUp" Then ' up
SortBy = Abs(SortBy)
ElseIf shp.ParentGroup.Name = "Dir_SortDown" Then ' down
SortBy = -1 * Abs(SortBy)
End If
CheckSortOption
End Sub
'기존 슬라이드와 개체 모두 지우기
Sub EraseAll()
Dim sld As Slide
Dim i As Integer
'2번 슬라이드부터 끝까지 삭제
For i = ActivePresentation.Slides.count To 2 Step -1
If i > 1 Then ActivePresentation.Slides(i).Delete
Next i
'1번 슬라이드에서 폴더명 제외하고 삭제
With ActivePresentation.Slides(1)
For i = .Shapes.count To 1 Step -1
If Left(.Shapes(i).Name, 4) <> "Dir_" Then .Shapes(i).Delete
Next
End With
End Sub
'그래프 그리기
Sub DrawGraph()
Dim SlideNo As Integer
Dim sld As Slide
Dim myLayout As CustomLayout
Dim shp As Shape
Dim eft As Effect
Dim MW As Single, MH As Single
Dim x As Single, y As Single, w As Single
Dim i As Integer
MW = ActivePresentation.PageSetup.SlideWidth
MH = ActivePresentation.PageSetup.SlideHeight
SlideNo = 1
For i = 1 To UBound(FileList)
With ActivePresentation.Slides(SlideNo).Shapes
x = Margin
y = Margin + TopMargin + ((i - 1) Mod 5) * Height * 3
w = MW - Margin * 2
'페이지 번호 표시
If i Mod 5 = 1 Then
Set shp = .AddTextbox(msoTextOrientationHorizontal, MW \ 2 - Height, MH - Margin, Margin + Height, Height)
shp.TextFrame.TextRange.Text = SlideNo & "/" & ((UBound(FileList) + 4) \ 5)
shp.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignCenter
shp.Name = "Page" & SlideNo
End If
'파일명 표시
Set shp = .AddTextbox(msoTextOrientationHorizontal, x, y, w, Height)
shp.TextFrame.TextRange.Text = FileList(i).FileName
shp.TextFrame.WordWrap = msoFalse
shp.Name = "file" & i
shp.ActionSettings(ppMouseClick).Action = ppActionRunMacro
shp.ActionSettings(ppMouseClick).Run = "RunPPT" '클릭시 PPT 불러오기
'막대그래프 표시
y = y + Height
w = w * FileList(i).FileSize / MaxSize ' Filesize * 1/100
Set shp = .AddShape(msoShapeRoundedRectangle, x, y, w, Height)
shp.Adjustments(1) = 1 '둥글게
shp.Fill.ForeColor.RGB = RGB(255 * (w / (MW - Margin * 2)), 125, 125)
shp.Name = "bar" & i
'animation 추가
Set eft = ActivePresentation.Slides(SlideNo).TimeLine.MainSequence.AddEffect(shp, _
msoAnimEffectFly, , msoAnimTriggerAfterPrevious, -1) 'msoAnimEffectExpand
eft.EffectParameters.Direction = msoAnimDirectionRight
eft.Timing.Duration = 0.25
'막대그래프 위에 파일사이즈 표시
w = MW - Margin * 2
Set shp = .AddTextbox(msoTextOrientationHorizontal, x, y, w, Height)
shp.TextFrame.TextRange.ParagraphFormat.Alignment = ppAlignRight
shp.TextFrame.WordWrap = msoFalse
shp.TextFrame.TextRange.Text = Format(FileList(i).FileSize, "0,000 bytes")
shp.Name = "size" & i
If i Mod 5 = 0 Then ' 5,10,15..5의 배수마다 새로운 슬라이드 추가
'이전 페이지 하단 다음페이지버튼 추가
Set shp = .AddTextbox(msoTextOrientationHorizontal, MW \ 2 + Margin, MH - Margin, Margin, Height)
shp.TextFrame.TextRange.Text = ">>"
shp.Name = "MoveR" & SlideNo
shp.ActionSettings(ppMouseClick).Action = ppActionNextSlide '애니매이션을 유지하려면 gotoSlide 를 이용
'슬라이드 추가
Set myLayout = ActivePresentation.Slides(SlideNo).CustomLayout
SlideNo = SlideNo + 1
Set sld = ActivePresentation.Slides.AddSlide(SlideNo, myLayout)
'폴더명 표시, 정렬옵션 등 복사
For Each shp In ActivePresentation.Slides(1).Shapes
If Left(shp.Name, 4) = "Dir_" Then
shp.Copy
With ActivePresentation.Slides(SlideNo).Shapes.Paste
'Group 을 복사하면 Parent/Child 성질을 잃어버리는 버그(?)를 보완
If shp.Type = msoGroup Then .Ungroup.Regroup.Name = shp.Name
End With
End If
Next shp
'새 페이지 하단 이전페이지버튼 추가
Set shp = ActivePresentation.Slides(SlideNo).Shapes.AddTextbox(msoTextOrientationHorizontal, _
MW \ 2 - Margin - Height, MH - Margin, Margin, Height)
shp.TextFrame.TextRange.Text = "<<"
shp.Name = "MoveL" & SlideNo
shp.ActionSettings(ppMouseClick).Action = ppActionPreviousSlide
End If
End With
Next i
End Sub
'textbox에 쓰여 있는 ppt 열기
Sub RunPPT(shp As Shape)
Presentations.Open (Target & "\" & shp.TextFrame.TextRange.Text)
End Sub
'폴더안 파일을 검색
Sub ScanDir()
Dim myFile As String
Dim count As Integer
With ActivePresentation.Slides(1).Shapes("Dir_Name").TextFrame
.TextRange.Text = Target
.WordWrap = msoFalse
End With
'배열 삭제
Erase FileList
'search for ppt files
count = 0
MaxSize = 0
myFile = Dir(Target & "\*.pp*") ' .ppt, .pps, .pptm, .ppsm ...
Do While myFile <> ""
'MsgBox myFile & ":" & FileLen(Target & "\" & myFile)
count = count + 1
ReDim Preserve FileList(1 To count)
'save filename and filesize
FileList(count).FileName = myFile
FileList(count).FileSize = FileLen(Target & "\" & myFile)
If FileList(count).FileSize > MaxSize Then MaxSize = FileList(count).FileSize ' 가장 큰 파일 크기를 구함
myFile = Dir
Loop
End Sub
' 폴더명을 선택
Function GetFolder() As String
Dim fileNo As Integer
Dim fd As FileDialog
Dim Target As String
Set fd = Application.FileDialog(msoFileDialogFolderPicker) '파일은 msoFileDialogFilePicker
With fd
.Title = "PPT가 있는 폴더를 선택하세요."
.Filters.Clear
.InitialFileName = ActivePresentation.Path & "\" '바탕화면은 Environ("USERPROFILE") & "\Desktop\"
.AllowMultiSelect = False
If .Show = True Then Target = .SelectedItems(1)
End With
Set fd = Nothing
GetFolder = Target
End Function
'슬라이드쇼 시작시 자동으로 매크로 시작
Sub OnSlideShowPageChange(ByVal SSW As SlideShowWindow)
If Started Then Exit Sub
If SSW.View.CurrentShowPosition = 1 Then
'MsgBox "first time"
Started = True
Start
End If
End Sub
Sub OnSlideShowTerminate(ByVal SSW As SlideShowWindow)
Started = False
End Sub
'개체(Shape)의 위치 등을 알아보기 위한 용도
Sub GetXYSize()
Dim x As Single, y As Single, w As Single, h As Single
With ActivePresentation.Slides(1).Shapes("Dir_Name")
x = .Left
y = .Top
w = .Width
h = .Height
MsgBox "x:" & x & " y:" & y & " w:" & w & " h:" & h & " line color:" & .Line.ForeColor.RGB
End With
End Sub
최근댓글