Hello
I am getting Bad File Name Error when Clicked on Listbox of Files. How to get rid of this Error
After getting rid of Error
Q1. How Can I get No of Pages of Each PDF File in textbox when cliked on listbox of files ?
Q2. Any ideas How i can view contents of Each Page no in Userform Image Box ?
FYI PDF are opened in MS-Edge.
Code:
Option Explicit
Dim xRg As Range
Dim xStr As String
Dim xFd As FileDialog
Dim xFdItem As Variant
Dim xFileName As String, xFolderPath As String, xFileExtnFilter As String, xStrData As String
Dim xFileNum As Long
Dim RegExp As Object
Dim xWdApp
Dim xWd
Public Sub DirPathNames()
Set xFd = Application.FileDialog(msoFileDialogFolderPicker)
With xFd
.Title = "Select the Folder..."
If .Show = -1 Then
xFdItem = xFd.SelectedItems(1)
txtFolderPath.Text = xFdItem
Else
MsgBox "No Folder Path Selected"
Exit Sub
End If
End With
xFolderPath = txtFolderPath.Text
xFileExtnFilter = "*.PDF"
If Dir(xFolderPath & "\" & xFileExtnFilter) = "" Then
MsgBox "There are no files of the type:" & vbCrLf & xFolderPath & "\" & xFileExtnFilter
Exit Sub
Else
xFileName = Dir(xFolderPath & "\" & xFileExtnFilter)
Do While xFileName <> ""
LstfileBx.AddItem xFolderPath & "\" & xFileName
xFileName = Dir
Loop
End If
End Sub
Private Sub LstfileBx_Click()
txtFolderPath.Text = LstfileBx.Text
Open txtFolderPath.Text For Binary As #xFileNum
xStrData = Space(LOF(xFileNum))
Get #xFileNum, , xStrData
Close #xFileNum
txtNoOfPAgesPDF.Text = RegExp.Execute(xStrData).Count
End Sub
SamD
65