Manage Learn to apply best practices and optimize your operations.

Howto: Copy Word Rich Text To The Clipboard

Introduction
This will describe how to:
1. get a word document that has been embedded into a rich text field in Notes,
2. activate it and start an OLE session,
3. select the contents, and then
4. copy this to the Windows clipboard.

After it is in the clipboard, it is up to you. I would use caution here. It is
better to avoid using the clipboard without the user knowing. It is possible
that the user has something in there already. If you overwrite it without
telling them, they may not like it.

Algorithm for the code:
1. open up a view,
2. get a document based on the first sorted column (the key),
3. Get the target rich text field,
4. activate the embedded word object,
5. select everything, and
6. copy it to the clipboard.

Note: to get additional help when your are in Lotus script. Open up the
'browser' and view the OLE objects. If you want help on any of these topics,
press F1.
Sub CopyWordtoClip(Byval viewname As String,_ 'The view name to copy
Byval dockey As String,_ 'The notes document's key
Byval fieldname As String,_ 'The field where the object is
ok) 'If it worked
'Name: Ian Connor
'Company: CSC
'Date: 3 June 1999

'PRE: The view exists, it has a document with the first column value equal
to the dockey and it has a word document
' with embedded into the field 'body'
'POST: The contents of the word embedded object are in the clipboard

'PURPOSE: To get the rich text contents of the Word embedded object into
the clipboard

ok = True

On Error Goto errorhandle

'Declare the stuff
Dim session As New NotesSession
Dim cdb As notesdatabase
Dim view As notesView ' Theview
Dim doc As notesdocument 'The document with the attachment
Dim item As Variant 'The rt item with the attachment
Dim embobj As NotesEmbeddedObject 'the attachment
Dim handle As Variant 'Handle to the Word Document
Dim selection As Variant 'The selction object in Word (the whole thing)

'Get the document in the current database given the view and key to use
Set cdb = session.CurrentDatabase
Set view = cdb.GetView( viewname )
Set doc = view.GetDocumentByKey( dockey )


'Get the object in the field
Set item = doc.getfirstitem(fieldname)
Set embobj = Item.EmbeddedObjects(0)

'Get the OLE handle and activate it (without display)
Set handle = embobj.Activate(False)

'Select everything
handle.select
Set selection = handle.activewindow.selection

'Copy the selection to the clipboard
selection.copy

Exit Sub

errorhandle:
Messagebox "OLE Copy Error", 16, Error
ok = False
Exit Sub

End Sub

Dig Deeper on Domino Resources - Part 4

SearchWindowsServer
Search400
  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/Search400.com community. These cheat ...

SearchDataCenter
SearchContentManagement
Close