Here the function, copy and paste it to vba module
Function GetProgFilesPath(ByVal sExecutable As String) As String
On Error GoTo Err_Exit
Dim obj As Object
Select Case LCase(sExecutable)
Case "winword.exe", "word.exe"
Set obj = CreateObject("Word.Application")
Case "excel.exe"
Set obj = CreateObject("Excel.Application")
Case "outlook.exe"
Set obj = CreateObject("Outlook.Application")
Case Else
MsgBox "Not Managed" & sExecutable, vbInformation
Exit Function
End Select
GetProgFilesPath = obj.path
Set obj = Nothing
Exit_Exit:
Exit Function
Err_Exit:
MsgBox "Err:GetProgFilesPath=" & Err.Description
Resume Exit_Exit
End Function
No comments:
Post a Comment