Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting pictures in Word from Powerbuilder using OLE

Status
Not open for further replies.

Athmaraman

Programmer
Jun 16, 2008
6
IN
Hi
I would like to insert images/pictures in Word using OLE from PB 7. Any kind of help is highly appreciated.
Thanks in advance
 
Should be something like...

String ls_pic
OLEObject obj_word, obj_doc

ls_pic = 'C:\SomePicture.bmp'

obj_word = CREATE OLEObject
obj_word.ConnectToNewObject( 'word.application' )

obj_doc = obj_word.Documents.Add( )
obj_doc.Shapes.AddPicture( ls_pic )


Keep in mind, I haven't tested this, but from the quick MSDN search I did, this is what I came up with.
 
Thanks for the reply. It works but....it places the picture at the top of the document. Infact what I would like to have is to have a couple of pictures at the end of the document and I would like to assign the path during run time based on some conditions ans also make it visible/invisible. Should I have an image control or picture in the word template for this? It would be great if you could you get me a sample script as well with the syntax of assigning the path and the visibility property.
 
As far as assigning the path dynamically at runtime, in the snippet above you could base this a number of different ways...

String ls_pic, ls_temp

//based on radio buttons
CHOOSE CASE TRUE
CASE rb_1.Checked
ls_pic = 'C:\pic1.bmp'
CASE rb_2.Checked
ls_pic = 'C:\pic2.bmp'
CASE ELSE
ls_pic = 'C:\pic_default.bmp'
END CHOOSE

//based on a single line edit
ls_pic = sle_1.Text
IF NOT FileExists( ls_pic ) THEN ls_pic = 'C:\pic_default.bmp'

//ask at runtime
GetFileOpenName( 'Choose Picture...', ls_pic, ls_temp, '', 'Image Files (*.bmp; *.jpg; *.jpeg), *.bmp; *.jpg; *.jpeg' )

//etc, etc, etc


As far as a script for inserting into the middle of the text... I'll have to dig & experiment a little further. In the meantime, you may want to look through the MSDN documentation for some starters...
 
Thanks again. I know what pictures I need to populate in advance which is not a problem. I also know what documents should be opened as well. My requirement is to place 4 pictures in Word and during runtime I will decide which of those should be made visible. What type of object should be placed in those Word documents at design time so that I can just populate the path for those objects in PB script? Should it be an image control or a picture or a drawing object? Can I refer with a name on those objects/controls in Word so that I can refer to those directly in PB script and assign just the path and also change the visibile property? I am searching in MSDN but getting no where! Thanks in advance.
 
MSDN is an acquired taste... LOL

Here's an article with some common methods/properties used to set an image in a Word document:
I believe you should be able to use something like this to manipulate the positioning of the image:

String ls_pic
Long ll_pic
OLEObject obj_doc

//ls_pic = your picture
//obj_doc = the document you're working with

ll_pic = obj_doc.Shapes.AddPicture( ls_pic )

//to reference the image you've just inserted...
obj_doc.Shapes( ll_pic ).[whatever]
 
It does not work. The only thing I can do is to AddPicture but I am unable to refer to the individual pictures. Is it possible to add pictures in the Word document itself and then refer to them from PB script which could be simpler? Help!!!
 
Have you tried referring to the picture like obj_doc.Shapes( "Picture 1" ).Select( )?

That should select it, and then you should be able to navigate it where you want it... You'll just have to figure out how the objects get named by doing a simple AddPicture( ) and then closing everything out, and opening Word, select the picture, and see what it's named as.

I'll do a bit of testing myself...
 
It works with the following code for pictures created dynamically from PB script:

lOLE.ActiveDocument.Shapes.AddPicture( ls_pic )lOLE.ActiveDocument.Shapes[1].Select( )
lOLE.ActiveDocument.Shapes[1].Height = 72
lOLE.ActiveDocument.Shapes[1].Visible= FALSE

I have another requirement where the pictures(jpeg) are already present in the word document (created using menu option Insert- Pictures - From file). How do I make those invisible/visible from PB script? If I use Shapes[] it gives an error. How can I access those pictures? Thanks in advance for your tips.
 
I want to say you should be able to use something like:

Long ll_cnt, ll_count

ll_count = OLE.ActiveDocument.Shapes.Count

FOR ll_cnt = 1 TO ll_count
OLE.ActiveDocument.Shapes( ll_cnt ).[method/property]
NEXT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top