Const MAX_FILENAME_LEN = 256
Const SHELL_NORMAL_FOCUS = 3
Declare Function FindExecutable Lib "shell32.dll" Alias "FindExecutableA" (Byval lpFile As String,_
Byval lpDirectory As String, Byval lpResult As String) As Long
Dim ui As New NotesUIWorkspace
Dim db As NotesDatabase
Dim collection As NotesDocumentCollection
Dim doc As NotesDocument
Dim rtfitme As Variant
Dim docHandle As Variant
Dim specObj As NotesEmbeddedObject
Dim tempDir As String
Dim tempFileName As String
Dim filePath As String
Dim exePath As String
Dim shellPath As String
Dim exeRes As Long
Set db = ui.CurrentDatabase.Database
Set collection = db.Search(|form="XXXX"|,Nothing,0)
Set doc = collection.GetFirstDocument
If doc Is Nothing Then
Msgbox "XXXX XXXX"
Else
Set rtfitem = doc.GetFirstItem("XXXX")
If rtfitem.Type = RICHTEXT Then
If Isempty(rtfitem.EmbeddedObjects) Then
Msgbox "XXXX XXXX"
Else
Set specObj = rtfitem.EmbeddedObjects(0)
tempDir$ = Environ("Temp")
tempFileName$ = specObj.Source
filePath$ = tempDir$ & "/" & tempFileName$
'save the attachment to the temp folder
Call specObj.ExtractFile(filePath$)
'create a buffer
exePath$ = Space$(MAX_FILENAME_LEN)
'find the executable
exeRes& = FindExecutable(filePath$,"",exePath$)
If exeRes& > 32 Then
exePath = Left$(exePath, Instr(exePath, Chr$(0)) - 1)
'open the file
exeRes = Shell(exePath$ & | "| & filePath$ & |"|,SHELL_NORMAL_FOCUS)
Else
Msgbox "No association found !"
End If
End If
Else
Msgbox "XXXX XXXX"
End If
End If