Add picture to Word via LotusScript

I am creating a Word doc from an agent and I need to add the company logo. I have it in the image resource lib and I have it on a RT field on a doc. Can someone give me code to do this?

The company I work for will not purchase any 3rd party tools

Thanks for any help

Subject: Add picture to Word via LotusScript

I suggest you record a macro in word to see what code you need.I did and got this:

Selection.InlineShapes.AddPicture FileName:= “C:\blahblah.jpg” , LinkToFile:=False, SaveWithDocument:=True

Now, that instruction won’t work very well in LotusScript, you’ll have to alter it slightly.

The Word help file says:

expression.AddPicture(FileName, LinkToFile, SaveWithDocument, Range)

expression Required. An expression that returns an InlineShapes object.

FileName Required String. The path and file name of the picture.

LinkToFile Optional Variant. True to link the picture to the file from which it was created. False to make the picture an independent copy of the file. The default value is False.

SaveWithDocument Optional Variant. True to save the linked picture with the document. The default value is False.

Range Optional Variant. The location where the picture will be placed in the text. If the range isn’t collapsed, the picture replaces the range; otherwise, the picture is inserted. If this argument is omitted, the picture is placed automatically.

So, in LotusScript you will need:

Selection.InlineShapes.AddPicture(“C:\blahblah.jpg”, False, True)

You will, of course, first need to extract the file from your RT-item to disk, but this should work.

Subject: RE: Add picture to Word via LotusScript

Thanks… i didnt think to extract it to disk first.

Subject: RE: Add picture to Word via LotusScript

a little sample:

i make a document conteining the logo image the document are like

field kw as text

field members as richtext

get the logo from a view save it in a temp directory and set a globale variable to link it and create a word obj and put it in word

Sub getLogo

fileLogo =  "c:\temp\Logo.gif"

Dim session As New NotesSession    

Dim db As NotesDatabase

Dim view As NotesView

Dim doc As NotesDocument    

Dim wsp As New notesuiworkspace

Dim source As notesuidocument



Dim rtitem As Variant

Set db = session.CurrentDatabase

Dim serverName As New NotesName(db.server)

Set view = db.GetView( "TG" )    

Set doc = view.GetDocumentByKey("Logo")  

Set rtitem = doc.GetFirstItem( "Members" )

Forall o In rtitem.EmbeddedObjects

	Call o.ExtractFile 	( filelogo)

End Forall

End Sub

Set objword = doc.CreateObject(“OLEObject”,note.~$OLEObjProgID(0))

.

.

.

Set logo = objword.application.activedocument.shapes.AddPicture (FileLogo, False, True)

Subject: RE: Add picture to Word via LotusScript

I’m trying to put your sample to use because I think it might help resolve an issue I’m having exporting a letter from Notes with a logo image on it into Word.

Anyway, I keep getting Variant Does Not Contain An Object error on the line:

Set objword = doc.CreateObject(“OLEObject”,note.~$OLEObjProgID(0))

I created a document with two fields: text , Members. I put Logo in the text field and the logo image in the RTF field. Is that right? Created a view called TG with that document in it. Pasted the sample in an agent and kicked it off manually…

Thanks in advance!!

Subject: RE: Add picture to Word via LotusScript

this method working in word 2k 2k3 and notes 6.x 7.x