Launch EXCEL and show add-in

I have an approval database that upon final approval, launches an excel spreadsheet that it attached to the document. My users have an excel add-in that allows them to upload the contents of the spreadsheet into SAP. However, when EXCEL launches from Notes, the add-in menu does not appear. When EXCEL is launched from windows, the add-in does appear. Please help me determine what is missing from my code that prevents the display of the add- in menu.

Here is my code:

Sub OpenMPU

Dim uiw As New NotesUIWorkspace

Dim uidoc As NotesUIDocument

Set uidoc = uiw.CurrentDocument



Dim s As New NotesSession

Dim db As NotesDatabase

Set doc = s.DocumentContext

Set db = s.CurrentDatabase



Set xlDoc = uidoc.Document

'get the attachment’s file name

Set attachedFile = xlDoc.GetFirstItem("MPUUpload")

fileName = attachedFile.EmbeddedObjects(0).Name

'get handle on object

Set object = xlDoc.GetAttachment(fileName )

'location of temporay file

fileLoc = "c:\" & object.Name

'extract attachment to temp file location

Call object.ExtractFile(fileLoc)

'open the temp file with excel

Set xlApp = CreateObject("Excel.application")

Set xlBook = xlApp.WorkBooks.Open(fileLoc)

If xlBook Is Nothing Then

	Set xlSheet = Nothing

	Set xlNewWkbk = Nothing

	Set xlWkbks = Nothing

	Set xlApp =Nothing 

	Msgbox "Cannot locate MPU Upload file."

	Exit Sub

End If

xlApp.Visible = True

End Sub

Subject: Launch EXCEL and show add-in

Lisa,

Use the Windows API ShellExecute or even Windows Scripting Host WScript.Shell to launch Excel (and the spreadsheet itself) …

Let me know if you need code.

Gary

Subject: RE: Launch EXCEL and show add-in

I do need code. I’ve never done this before. Please help.

Subject: RE: Launch EXCEL and show add-in

Lisa,

Here’s a very simple implementation of the ShellExecute Windows API. NOTE: It will launch ANY program – not just Excel – it will determine, from the filename extension, which program to launch and attempt to launch it. It will return True if it is successful or False if it fails. Plug the code into a BUtton in a Notes form to test it and see how it works.

Gary

REM Declarations for Windows API – ShellExecute

Declare Function ShellExecute Lib _

“shell32.dll” Alias “ShellExecuteA” _

(Byval hwnd As Long, _

Byval lpOperation As String, _

Byval lpFile As String, _

Byval lpParameters As String, _

Byval lpDirectory As String, _

Byval nShowCmd As Long) As Long

Sub Click(Source As Button)

    REM  This code is in a button for testing -- you could use it virtually anywhere

    Dim success As Variant        

    Const FileToLaunch = "c:\Test.xls"  '  VALID File Name for testing -- you will replace it with your object.Name reference

’ Const FileToLaunch = “c:\oopsTest.xls” ’ INVALID filename for testing treturn values

    success = LaunchFile( FileToLaunch )

    If Not success Then Msgbox "Error launching " & FileToLaunch

End Sub

Function LaunchFile( FileToLaunch ) As Boolean

    REM  Implements the ShellExecute Windows API

    REM  Returns True if successful (File exists and was able to launch the program associated with it)

    REM  Returns False if failure (File does not exist or was NOT able to launch the program associated with it)

    LaunchFile = False

    Dim iret As Long

    Dim intReturnValue As Integer

    Const SW_SHOWNORMAL = 1

    iret = ShellExecute( 0, _

    "Open", _

    FileToLaunch, _

    "", _

    "c:\", _

    SW_SHOWNORMAL )

    intReturnValue = Cint( iret ) - 32

    If intReturnValue > 0 Then        

            LaunchFile = True        

    Else

            LaunchFile = False

    End If

End Function

Subject: RE: Launch EXCEL and show add-in

Gary,

Your solution worked great - thanks much! I have noticed that this solution keeps the focus on Notes after the Excel file has opened. Is there anyway to move the focus to Excel? I have a prompt that asks the users if the upload to SAP was successful so I need them to go to Excel to do the upload. Then when they return to Notes, the prompt will be there.