Link to home
Start Free TrialLog in
Avatar of Raybone
Raybone

asked on

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
Avatar of Alex_Gould
Alex_Gould

Hi,

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 http://www.redbooks.ibm.com/abstracts/sg244856.html

HTH,

Alex
Avatar of Raybone

ASKER

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,

Raybone
ASKER CERTIFIED SOLUTION
Avatar of ewerfel
ewerfel

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Raybone

ASKER

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
     Application.Quit
     Kill FileName
     Set MyDoc = Nothing
     Set Application = Nothing
     Exit Sub
     
ErrorHandler:
     Exit Sub
     Messagebox "Error" & Str(Err) & ": " & Error$
     Resume Next
     
End Sub