|
ゴメン本題の方は、以下の様かな?
Option Explicit
Public Sub Sample()
Const cnsTITLE = "List file name in the folder"
Const cnsDIR = "\*.*"
Dim i As Long
Dim lngRow As Long
Dim vntPATHNAME As Variant
Dim strFileName As String
Dim vntResult As Variant
vntPATHNAME = Application.InputBox("Input folder address.", cnsTITLE, "C:\")
If VarType(vntPATHNAME) = vbBoolean Then
Exit Sub
Else
If Right(vntPATHNAME, 1) <> "\" Then
vntPATHNAME = vntPATHNAME & "\"
End If
End If
'check input
If Dir(vntPATHNAME, vbDirectory) = "" Then
MsgBox "There is no input folder.", vbExclamation, cnsTITLE
Exit Sub
End If
ReDim vntResult(1 To 4)
With Workbooks.Add.Worksheets(1)
lngRow = 1
.Cells(lngRow, "A").Resize(, 4).Value _
= Array("No.", "FileName", "DateTime", "Size(KB)")
lngRow = lngRow + 1
'get top file name
strFileName = Dir(vntPATHNAME & cnsDIR, vbNormal)
Do While strFileName <> ""
vntResult(1) = lngRow - 1
vntResult(2) = strFileName
vntResult(3) _
= Format(CDate(FileDateTime(vntPATHNAME & strFileName)), _
"yyyy/mm/dd h:mm:ss")
vntResult(4) = FileLen(vntPATHNAME & strFileName) \ 1024
.Cells(lngRow, "A").Resize(, 4).Value = vntResult
lngRow = lngRow + 1
strFileName = Dir
Loop
.Cells.EntireColumn.AutoFit
End With
End Sub
|
|