I was pointed in a direction on what I could change in my code that I have been working on but with the changes I am getting 2 different errors. The errors I am receiving are the following, One error is a compile error: syntax error and the other is compile error: Expected:=.
This is the code I am working with right now. The coding in red is my issue I think
Sub PDFPageNumbers()
Dim FSO As Object
Dim F_Folder As Object
Dim F_File As Object
Dim IterateFolders As String 'I added this in trying to figure the issue out
Dim Selected_Items As String
Dim DialogFolder As FileDialog
Dim Acrobat_File As Acrobat.AcroPDDoc
Dim i As Long
'Select PDF Directory
Set DialogFolder = Application.FileDialog(msoFileDialogFolderPicker)
If DialogFolder.Show = -1 Then
Selected_Items = DialogFolder.SelectedItems(1)
Else: Set DialogFolder = Nothing
End If
Set DialogFolder = Nothing
Set FSO = CreateObject("Scripting.FileSystemObject")
Set F_Folder = FSO.GetFolder(Selected_Items)
IterateFolders(F_Folder, i)
i = 2
Sub IterateFolders(ByVal F_Folder, ByRef i)
For Each SubFolder In F_Folder
IterateFolders(SubFolder, i)
Next
For Each F_File In F_Folder.Files
Selected_Items = UCase(F_File.Path)
If Right(Selected_Items, 4) = ".PDF" Then
Set Acrobat_File = New Acrobat.AcroPDDoc
Acrobat_File.Open Selected_Items
Cells(i, 1).Value = Selected_Items
Cells(i, 2).Value = Acrobat_File.GetNumPages
i = i + 1
Acrobat_File.Close
Set Acrobat_File = Nothing
End If
Next
End Sub
Range("A:B").Columns.AutoFit
Set F_File = Nothing
Set F_Folder = Nothing
Set FSO = Nothing
End Sub
This is the original code, the code in blue is what I cut out
Sub PDFPageNumbers()
Dim FSO As Object
Dim F_Folder As Object
Dim F_File As Object
Dim Selected_Items As String
Dim DialogFolder As FileDialog
Dim Acrobat_File As Acrobat.AcroPDDoc
Dim i As Long
'Select PDF Directory
Set DialogFolder = Application.FileDialog(msoFileDialogFolderPicker)
If DialogFolder.Show = -1 Then
Selected_Items = DialogFolder.SelectedItems(1)
Else: Set DialogFolder = Nothing
End If
Set DialogFolder = Nothing
Set FSO = CreateObject("Scripting.FileSystemObject")
Set F_Folder = FSO.GetFolder(Selected_Items)
i = 2
For Each F_File In F_Folder.Files
Selected_Items = UCase(F_File.Path)
If Right(Selected_Items, 4) = ".PDF" Then
Set Acrobat_File = New Acrobat.AcroPDDoc
Acrobat_File.Open Selected_Items
Cells(i, 1).Value = Selected_Items
Cells(i, 2).Value = Acrobat_File.GetNumPages
i = i + 1
Acrobat_File.Close
Set Acrobat_File = Nothing
End If
Next
Range("A:B").Columns.AutoFit
Set F_File = Nothing
Set F_Folder = Nothing
Set FSO = Nothing
End Sub
This is the code that I pasted in.
Set F_Folder = FSO.GetFolder(Selected_Items)
IterateFolders(F_Folder, i)
.....
Sub IterateFolders(ByVal F_Folder, ByRef i)
For Each SubFolder In F_Folder
IterateFolders(SubFolder, i)
Next
For Each F_File In F_Folder.Files
Selected_Items = UCase(F_File.Path)
If Right(Selected_Items, 4) = ".PDF" Then
Set Acrobat_File = New Acrobat.AcroPDDoc
Acrobat_File.Open Selected_Items
Cells(i, 1).Value = Selected_Items
Cells(i, 2).Value = Acrobat_File.GetNumPages
i = i + 1
Acrobat_File.Close
Set Acrobat_File = Nothing
End If
Next
End Sub
I don't think IterateFolders is defined. I am confused.
Thanks for the help.
Bookmarks