Hi I want to be able to have the user input a part number and be able to open the .pdf. However the file location name varies due to old folder naming so I want to search a folder and subfolders for the part. I have a code but it only opens the pdf if the file location is correct. The files will be in X:\Projects\[Serial Number] then it needs to search the subfolders and open. I am stuck thanks for the help!
Dim PartNumberEntry As String
Dim PDFFilePath As String
Dim SerialNumberCode As String
PartNumberEntry = UserPartNumberInput.Text
Function OpenAnyFile(strPath As String)
Set objShell = CreateObject("Shell.Application")
If FileThere(strPath) Then
objShell.Open (strPath)
Else
MsgBox ("File Not Found")
End If
End Function
Function FileThere(FileName As String) As Boolean
If (Dir(FileName) = "") Then
FileThere = False
Else
FileThere = True
End If
End Function
Private Sub CommandButton1_Click()
With CommandButton1
.SpecialEffect = 0
.BackColor = &HC0FFC0
End With
SerialNumberCode = Left(PartNumberEntry, 4)
'Open PDF
PDFFilePath = "X:\Projects\" & SerialNumberCode
Call OpenAnyFile(PDFFilePath)
SerialNumberCode = Left(PartNumberEntry, 4)
End sub
'Open PDF
PDFFilePath = "X:\Projects\" & SerialNumberCode
Call OpenAnyFile(PDFFilePath)
Dim PartNumberEntry As String
Dim PDFFilePath As String
Dim SerialNumberCode As String
PartNumberEntry = UserPartNumberInput.Text
Function OpenAnyFile(strPath As String)
Set objShell = CreateObject("Shell.Application")
If FileThere(strPath) Then
objShell.Open (strPath)
Else
MsgBox ("File Not Found")
End If
End Function
Function FileThere(FileName As String) As Boolean
If (Dir(FileName) = "") Then
FileThere = False
Else
FileThere = True
End If
End Function
Private Sub CommandButton1_Click()
With CommandButton1
.SpecialEffect = 0
.BackColor = &HC0FFC0
End With
SerialNumberCode = Left(PartNumberEntry, 4)
'Open PDF
PDFFilePath = "X:\Projects\" & SerialNumberCode
Call OpenAnyFile(PDFFilePath)
SerialNumberCode = Left(PartNumberEntry, 4)
End sub
'Open PDF
PDFFilePath = "X:\Projects\" & SerialNumberCode
Call OpenAnyFile(PDFFilePath)