Sub Pocet_stran()
Dim xStr As String, xFdItem As String, xFileName As String
Dim xFileNum As Long, Count As Long
Dim RegExp As Object, FSO As Object, File As Object
Dim F()
With Application.FileDialog(msoFileDialogFolderPicker)
If .Show <> -1 Then MsgBox "Nevybrali ste žiadny adresár": Exit Sub
xFdItem = .SelectedItems(1) & IIf(Right$(.SelectedItems(1), 1) = Application.PathSeparator, "", Application.PathSeparator)
End With
wsOld.UsedRange.ClearContents
With wsCiel.Range("A1:C1").Resize(wsCiel.Cells(Rows.Count, 1).End(xlUp).Row)
wsOld.Range("A1:C1").Resize(.Rows.Count).Value = .Value
.Offset(1, 0).ClearContents
End With
Set FSO = CreateObject("Scripting.FileSystemObject")
Set RegExp = CreateObject("VBscript.RegExp")
With FSO.GetFolder(xFdItem)
For Each File In .Files
xFileName = File.Name
If LCase(FSO.GetExtensionName(xFileName)) = "pdf" Then
Count = Count + 1
ReDim Preserve F(1 To 3, 1 To Count)
F(1, Count) = xFileName
F(3, Count) = File.DateLastModified
With RegExp
.Global = True
.Pattern = "/Type\s*/Page"
xFileNum = FreeFile
Open (xFdItem & xFileName) For Binary As #xFileNum
xStr = Space(LOF(xFileNum))
Get #xFileNum, , xStr
Close #xFileNum
F(2, Count) = .Execute(xStr).Count
End With
End If
Next File
End With
If Count > 0 Then
wsCiel.Range("A2:C2").Resize(Count).Value = Application.Transpose(F)
wsCiel.Columns("A:C").AutoFit
Else
MsgBox "Žiadne súbory PDF"
End If
Set FSO = Nothing: Set RegExp = Nothing: Set File = Nothing
End Sub