Option Compare Database

Option Explicit

 

' 08/19/2008

'      the purpose of this module is to find either Adobe Acrobat or Reader

'      so we can use the VBA Shell() command to open a PDF file

'      Shell() can automatically find programs like WINWORD.EXE or EXCEL.EXE

'      but    1) Adobe may not be in the PATH

'      and 2) the user may have either the Reader or the full Acrobat

 

' this code requires a reference to the Microsoft Scripting Runtime

'      usually found at C:\WINDOWS\system32\scrrun.dll

 

' this code was adapted from the article

'   Extreme file and folder scripting

'   http://blogs.msdn.com/gstemp/archive/2004/08/10/212113.aspx

 

Function GetAdobeReader() As String

    Dim fso As FileSystemObject

    Dim oFolder As Folder, oFile As File

    Dim sFolder As String, sAdobe As String

    ' set the starting point

    sFolder = "C:\Program Files\Adobe"

    '

    Set fso = CreateObject("Scripting.FileSystemObject")

    Set oFolder = fso.GetFolder(sFolder)

    GetAdobeReader = GetAdobeReader_Sub(oFolder)

End Function

   

Function GetAdobeReader_Sub(oFolder As Folder) As String

    Dim oSubFolder As Folder, oFile As File

    Dim sAdobe As String

    '

    ' look in all subfolders

    For Each oSubFolder In oFolder.SubFolders

        For Each oFile In oSubFolder.Files

            Select Case oFile.Name

                Case "acrobat.exe", "acroread.exe", "AcroRd32.exe"

                    GetAdobeReader_Sub = oFile.ParentFolder & "\" & oFile.Name

                    Exit Function

            End Select

        Next oFile

        sAdobe = GetAdobeReader_Sub(oSubFolder)

    Next oSubFolder

    GetAdobeReader_Sub = sAdobe

End Function