I never imagined printing embedded excel objects from a view would cause so much trouble, it looked fairly simple before I started working on it. I started off by writing a simple function, which looped through all the objects in a richtext field, but doesn't seem to work with excel objects saved in 97 format. After spending about four hours trying to find the reason I gave up and wrote this other function which works fine with all versions of excel. As the second function only gets the object by name, which is fine with the application here as we have only one embedded object to print per document.
Here's the first function which should have worked fine but didn't:
Sub PrintEmbeddedStuff(doc As notesdocument) On Error Resume Next If doc.hasembedded=False Then Exit Sub Dim handle As Variant Forall o In doc.EmbeddedObjects Print o.Name & " - " & o.Type & " - " & o.Class If o.Type = EMBED_OBJECT Then Set o1 = o Set handle=o.Activate(True) ' show If Not handle Is Nothing Then Call handle.PrintOut() ' prints the whole thing. Call handle.Quit() ' close the object, if it hasnt done so already End If Delete handle End If End Forall End Sub
Here's the second function which seem to work fine with all versions but only prints one object per document.
Sub PrintEmbeddedStuff(doc As notesdocument) On Error Resume Next If doc.hasembedded=False Then Exit Sub Dim handle As Variant Dim ws1 As Variant Dim o1 As notesembeddedobject Set ws1 = doc.getfirstitem("Rates") If Not (ws1 Is Nothing) Then Set o1 = ws1.getembeddedobject("Microsoft Excel Worksheet") If Not (o1 Is Nothing) Then Dim idisp As Variant Set idisp = o1.activate(True) Call idisp.PrintOut() ' prints the whole thing. Call idisp.Quit() ' close the object, if it hasnt done so already End If Delete idisp End If end function