In the declarations section of a button put:
Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type
Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type
Declare Function WaitForSingleObject Lib "kernel32" (Byval _
hHandle As Long, Byval dwMilliseconds As Long) As Long
Declare Function CreateProcessA Lib "kernel32" (Byval _
lpApplicationName As Long, Byval lpCommandLine As String, Byval _
lpProcessAttributes As Long, Byval lpThreadAttributes As Long, _
Byval bInheritHandles As Long, Byval dwCreationFlags As Long, _
Byval lpEnvironment As Long, Byval lpCurrentDirectory As Long, _
lpStartupInfo As STARTUPINFO, lpProcessInformation As _
PROCESS_INFORMATION) As Long
Declare Function CloseHandle Lib "kernel32" (Byval _
hObject As Long) As Long
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const INFINITE = -1&
Add a subroutine to the button:
Sub ExecCmd(cmdline$)
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
' Initialize the STARTUPINFO structure:
start.cb = Len(start)
' Start the shelled application:
ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, _
NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
' Wait for the shelled application to finish:
ret& = WaitForSingleObject(proc.hProcess, INFINITE)
ret& = CloseHandle(proc.hProcess)
End Sub
Put this in the click event:
' This button has loads of code in to make sure the edit process has finished
Dim uiw As New notesuiworkspace
Dim uidoc As notesuidocument
Set uidoc = uiw.currentdocument
Dim doc As notesdocument
Set doc = uidoc.document
If uidoc.isnewdoc Then
Msgbox "This utility doesn't work for new documents, save the document ( Ctrl S ), and try again."
End
End If
Set rtitem = doc.GetFirstItem( "Body" )
If ( rtitem.Type = RICHTEXT ) Then
Forall o In rtitem.EmbeddedObjects
If ( o.Type = EMBED_ATTACHMENT ) Then
Call o.ExtractFile( "c:\temp\" & o.Source )
fname=o.source
If Ucase$( Right$(fname,4)) = ".DOC" Or Ucase$( Right$(fname,4)) = ".DOT" Then
exeToUse = "C:\Program Files\Microsoft Office\Office\WINWORD.EXE"
On Error Goto ErrHdlr
fdt = Filedatetime ( exetouse )
Elseif Ucase$( Right$(fname,4)) = ".XLS" Or Ucase$( Right$(fname,4)) = ".XLB" Then
exeToUse = "C:\Program Files\Microsoft Office\Office\EXCEL.EXE"
On Error Goto ErrHdlr
fdt = Filedatetime ( exetouse )
Elseif Ucase$( Right$(fname,4)) = ".POT" Or Ucase$( Right$(fname,4)) = ".PPS" Or Ucase$( Right$(fname,4)) = ".PPT" Then
exeToUse = "C:\Program Files\Microsoft Office\Office\POWERPNT.EXE"
On Error Goto ErrHdlr
fdt = Filedatetime ( exetouse )
Elseif Ucase$( Right$(fname,4)) = ".TXT" Then
exeToUse = "notepad.exe "
Else
Msgbox "Sorry don't know which application to use!"
End
End If
ExecCmd exeToUse & " " & "C:\temp\" & o.source & ""
Msgbox "File " & o.source & " saved to c:\temp, save and exit application to reattach it to this document."
Msgbox "Process Finished"
Call o.Remove
Set object = rtitem.EmbedObject _
( EMBED_ATTACHMENT, "", "c:\temp\" & fname )
Call doc.Save( True, True )
Call uidoc.close
Call uiw.editdocument( True, doc)
'only do the first attachment
End
End If
End Forall
End If
ErrHdlr:
If Err=53 Then
' ok the application hasn't been found
Msgbox "Sorry cannot find the application executable file at : " & exetouse
End
End If
Print "Error: " & Error$ & " " & Err
End