0

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 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)
Scott Craner
  • 137,650
  • 9
  • 45
  • 77

0 Answers0