MS Office Automation from Notes

I've got a Notes database that has RTF & Excel files embedded in documents. I've imported the data into an RTF field in the docs, but I lose the formatting available in the native apps (MS Word & Excel). This is OK for viewing, but I'd like to use the MS Office applications to print the attachments (automatically via a script action).

I have no problem doing this from VB or VBA, but in the MS products, all you need to do to access the Office objects is click Tools/References & select the appropriate classes. How can I reference the MS Office objects from within Notes. An example showing how to print would be appreciated, however, once I can get at the object models, any MS Office functionality would be available.

I'm on Notes 4.6.1a & using Office 97-SR2.

Thanks In Advance
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


For Notes Automation to work you'll need Notes installed on the workstation it is running from.

LotusScript has a DoVerb() which you can use against NotesEmbeddedObject objects.

You may find it easier getting a handle to the objects via automation from the MS Office application instead.

Create VB script as if it were LotusScript, dim all your Notes variables as 'object' instead of Notes specific (NotesSession, NotesDatabase etc) and you'll be fine.

You'll find all the answers in the Redbook at


RayboneAuthor Commented:
I already tried the DoVerb Method of the Notes Embedded Object, but what I have are RTF file attachments. When I get into debug mode & access the object, I find that there are no verbs associated with it to execute.

Your answer refers to automating Notes from MS Office, but my need is to print these attachments from within Notes. The only reason I asked about Office Automation was that so far, the only way I've been able to satisfactorily print the RTF documents was by using either the Notes Viewer or MS Word. I've been told that you can't program to the Notes Viewer - the objects haven't been exposed - so my only option was Word.

I've since been able to successfully print using Word via Notes script. My current problem is knowing when Word is finished spooling the print job so that I can set the instance to Nothing & reclaim the memory afterwards. I've tried getting into a loop using DoEvents for nn seconds, but I'm not to happy with this solution since it will take different amounts of time to print on different PC's & I don't want to tie up the resources for too long.

Any suggestions you could give, either to know when Word is done printing, or perhaps a simpler way to accomplish the printing of an attached RTF document from Notes, would be greatly appreciated.

Thank You,

You should be able to use some variation of the following.  Get a handle to the embedded object, activate the object, then use the object's methods.  This example is for a spreadsheet.  VBA lets you pass an associative array as parameters (key:=value), but you'll have to use ordered parameters from Lotusscript.

     Dim workspace As New NotesUIWorkspace
     Dim uiDoc As NotesUIDocument
     Dim doc As NotesDocument
     Dim rtItem As NotesRichTextItem
     Dim object As NotesEmbeddedObject
     Dim spreadSheet as Variant
     Set uiDoc = workspace.CurrentDocument
     Set doc = uiDoc.Document
     Set rtItem = doc.GetFirstItem("Body")
     Set object = rtItem.embeddedObjects(0)
     Set spreadSheet = object.Activate(False)
     Call spreadSheet.PrintOut(1, 1, 1)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RayboneAuthor Commented:
I appreciate all your efforts, but this information did not help. I was able to resolve this situation myself with the following code in an Action Button:

Sub Click(Source As Button)
     On Error Goto ErrorHandler
     Dim workspace As New NotesUIWorkspace
     Dim uidoc As NotesUIDocument
     Set uidoc = workspace.CurrentDocument
     Dim Doc As NotesDocument
     Set Doc = uidoc.Document
     Dim rtitem As Variant
     Dim FileName As String
    ' Extract the attachment to a unique file
     Set rtitem = Doc.GetFirstItem( "FileToAppend" )
     If ( rtitem.Type = RICHTEXT ) Then
          Forall o In rtitem.EmbeddedObjects
               If o.Type = EMBED_ATTACHMENT  Then
                    filename = "C:\Windows\Temp\" + Format(Now,"yyyymmddhhnns")+ o.Name
                    Call o.ExtractFile ( filename )
               End If
          End Forall
     End If
     'Start Word then print the document
     Set Application = CreateObject("Word.application.8")
     Call Application.Documents.Open(FileName)
     Set myDoc = Application.Documents(1)
     myDoc.PrintOut (False) ' The false option is for Background & tells Word to wait until action is done to continue code. Prevents the
                                                    ' Next few lines from killing word before it's done printing.
'   Kill Word & the file, then release the memory
     Kill FileName
     Set MyDoc = Nothing
     Set Application = Nothing
     Exit Sub
     Exit Sub
     Messagebox "Error" & Str(Err) & ": " & Error$
     Resume Next
End Sub
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Lotus IBM

From novice to tech pro — start learning today.