Sub Sample2()
Dim buf As String, i As Long
Const P As String = "C:\Windows\System32\"
Range("A1") = "名前"
Range("B1") = "サイズ"
Range("C1") = "日時"
Range("A1:C1").HorizontalAlignment = xlCenter
buf = Dir(P & "*.*")
Do While buf <> ""
With Cells(Rows.Count, 1).End(xlUp)
.Offset(1, 0).Select
Selection = buf
.Offset(1, 1).Select
Selection = FileLen(P & buf)
.Offset(1, 2).Select
Selection = FileDateTime(P & buf)
End With
buf = Dir()
Loop
With ActiveSheet.PageSetup
.TopMargin = Application.InchesToPoints(0)
.BottomMargin = Application.InchesToPoints(0)
End With
Range("A1").CurrentRegion.Sort Range("B1"), xlDescending
For i = 2 To Cells(Rows.Count, 2).End(xlUp).Row
Cells(i, 2).Select
Selection.NumberFormat = "#,##0"
Next i
Range("A1:C1").EntireColumn.AutoFit
Range("A1").Select
End Sub
Sub Sample2()
Dim buf As String, i As Long
Const P As String = "C:\Windows\System32\"
Debug.Print Time
Range("A1") = "名前"
Range("B1") = "サイズ"
Range("C1") = "日時"
Range("A1:C1").HorizontalAlignment = xlCenter
buf = Dir(P & "*.*")
Do While buf <> ""
With Cells(Rows.Count, 1).End(xlUp)
.Offset(1, 0).Select
Selection = buf
.Offset(1, 1).Select
Selection = FileLen(P & buf)
.Offset(1, 2).Select
Selection = FileDateTime(P & buf)
End With
buf = Dir()
Loop
With ActiveSheet.PageSetup
.TopMargin = Application.InchesToPoints(0)
.BottomMargin = Application.InchesToPoints(0)
End With
Range("A1").CurrentRegion.Sort Range("B1"), xlDescending
For i = 2 To Cells(Rows.Count, 2).End(xlUp).Row
Cells(i, 2).Select
Selection.NumberFormat = "#,##0"
Next i
Range("A1:C1").EntireColumn.AutoFit
Range("A1").Select
Debug.Print Time
End Sub
Sub Sample4()
Dim buf As String, i As Long, S As Long
Const P As String = "C:\Windows\System32\"
Debug.Print Time & " - スタート"
Range("A1") = "名前"
Range("B1") = "サイズ"
Range("C1") = "日時"
Range("A1:C1").HorizontalAlignment = xlCenter
Debug.Print Time & " - セルの代入"
buf = Dir(P & "*.*")
Do While buf <> ""
With Cells(Rows.Count, 1).End(xlUp)
.Offset(1, 0).Select
Selection = buf
.Offset(1, 1).Select
Selection = FileLen(P & buf)
.Offset(1, 2).Select
Selection = FileDateTime(P & buf)
End With
buf = Dir()
Loop
Debug.Print Time & " - ファイル情報の取得"
With ActiveSheet.PageSetup
.TopMargin = Application.InchesToPoints(0)
.BottomMargin = Application.InchesToPoints(0)
End With
Debug.Print Time & " - 印刷の設定"
Range("A1").CurrentRegion.Sort Range("B1"), xlDescending
Debug.Print Time & " - 並べ替え"
For i = 2 To Cells(Rows.Count, 2).End(xlUp).Row
Cells(i, 2).Select
Selection.NumberFormat = "#,##0"
Next i
Debug.Print Time & " - 桁区切り書式設定"
Range("A1:C1").EntireColumn.AutoFit
Range("A1").Select
Debug.Print Time & " - 列幅の自動調整"
End Sub