I am trying to use the following code to open a pdf file from a folder, but I keep getting the "File not found" error.
Is there something I am missing? Below if the whole code if needed.
Code:
Shell "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Adobe Acrobat DC.exe " & FullPath & """, vbMinimizedFocus"
Is there something I am missing? Below if the whole code if needed.
Code:
Sub OpenPDFs()
Dim C As Collection, C1 As Collection, C2 As Collection, C3 As Collection, C4 As Collection, subFolder As Variant, subFolder1 As Variant, _
subFolder2 As Variant, subFolder3 As Variant, sFolder As String, File As Variant, WB1 As Workbook, FullPath As String
Application.ScreenUpdating = False
'Sets Open workbook as WB1
Set WB1 = ActiveWorkbook
'Allows user to select Directory folder
sFolder = GetFolder()
'Sets all subfolders in Directory to Collection
Set C = GetFoldersIn(sFolder)
'Sets all subfolders of subfolder in Directory to Collection
For Each subFolder In C
If subFolder = "." Or subFolder = ".." Then
Else
' Debug.Print "Folder Path " & sFolder & "\" & subFolder
Set C1 = GetFoldersIn(sFolder & "\" & subFolder)
For Each subFolder1 In C1
If subFolder1 = "." Or subFolder1 = ".." Then
Else
' Debug.Print "Folder Path " & sFolder & "\" & subFolder & "\" & subFolder1
Set C2 = GetFoldersIn(sFolder & "\" & subFolder & "\" & subFolder1)
For Each subFolder2 In C2
If subFolder2 = "ParticleData" Then
' Debug.Print "Folder Path " & sFolder & "\" & subFolder & "\" & subFolder1 & "\" & subFolder2
Set C3 = GetFoldersIn(sFolder & "\" & subFolder & "\" & subFolder1 & "\" & subFolder2)
For Each subFolder3 In C3
If subFolder3 = "ParticleDataReports" Then
' Debug.Print "Folder Path " & sFolder & "\" & subFolder & "\" & subFolder1 & "\" & subFolder2 & "\" & subFolder3
Set C4 = GetFilesIn(sFolder & "\" & subFolder & "\" & subFolder1 & "\" & subFolder2 & "\" & subFolder3)
For Each File In C4
' Debug.Print File
FullPath = sFolder & "\" & subFolder & "\" & subFolder1 & "\" & subFolder2 & "\" & subFolder3 & "\" & File
Debug.Print FullPath
' Shell "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Adobe Acrobat DC.exe " & FullPath & """, vbMinimizedFocus"
Next File
End If
Next subFolder3
End If
Next subFolder2
End If
Next subFolder1
End If
Next subFolder
Application.ScreenUpdating = True
End Sub
Function GetFilesIn(Folder As String) As Collection
Dim F As String
Set GetFilesIn = New Collection
F = Dir(Folder & "\*")
Do While F <> ""
GetFilesIn.Add F
F = Dir
Loop
End Function
Function GetFoldersIn(Folder As String) As Collection
Dim F As String
Set GetFoldersIn = New Collection
F = Dir(Folder & "\*", vbDirectory)
Do While F <> ""
If GetAttr(Folder & "\" & F) And vbDirectory Then GetFoldersIn.Add F
F = Dir
Loop
End Function
Function GetFolder() As String
Dim fldr As FileDialog
Dim sItem As String
Set fldr = Application.FileDialog(msoFileDialogFolderPicker)
With fldr
.Title = "Select a Folder"
.AllowMultiSelect = False
.InitialFileName = Application.DefaultFilePath
If .Show <> -1 Then GoTo NextCode
sItem = .SelectedItems(1)
End With
NextCode:
GetFolder = sItem
Set fldr = Nothing
End Function