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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word Automation - Replace Text with Picture

Status
Not open for further replies.

csr

Programmer
Jul 20, 2000
507
I have a table within a word document and I wish to place a signature in a cell that contains a particular line of text. I would like to do a search and replace to accomplish this but find no way to replace text with a graphic. Any help on this ?

Don


 
Look at the selection.inlineshapes.addpicture method in the vba object browzer of word

vba syntax from help file
Function AddPicture(FileName As String, [LinkToFile], [SaveWithDocument], [Range])

If you can put your cursor on the insertion point and call this with the correct syntax it will put the picture into the cell. By default the cell will stretch and this may be a problem.

 
Hi Don,

Here's the code I've used to achieve this. I'm not claiming it's perfect, but it does seem to work.

The "place-holder" text that I am replacing here is "{{signature}}" (without the quotes). I'm also inserting the user's name and job title.

Code:
* Get the text of the letter into a local variable
lcText = UPPER(thisform.oDoc.content.text)

* Does it contain the signature place-holder?
lnStartPos = AT("{{SIGNATURE}}", lcText)
IF lnStartPos = 0
  * Place-holder not present
   RETURN
ENDIF  

* Get a reference to the document range (we can't simply pass lnStartPos
* to the Range method, because that won't take account of the mailmerge
* fields)
lnStart = thisform.oDoc.Characters(lnStartPos).Start 
lnEnd =lnStart + LEN("{{Signature}}") 
loRange = thisform.oDoc.Range(lnStart, lnEnd)

* Delete the place-holder and insert the signature text
lcSigText = CHR(13) + csrSignatures.UserName + ;
  CHR(13) + csrSignatures.JobTitle
loRange.Delete
loRange.InsertAfter(lcSigText)

* Insert the signature graphic (we need to recreate the range object
* otherwise the graphic would overwrite the old range; the new range is just 
* one char. long)
loNewRange = thisform.oDoc.Range(lnStart-1, lnStart-1)
loNewRange.InLineShapes.AddPicture(csrSignatures.SigFile)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Hi Mike,

This statement works fine if the text is in the main body of the document.

lcText = UPPER(thisform.oDoc.content.text)

However, you may not have noticed ... my text is within a table cell.

I tried this ...

lcText = upper(oTable.cell(2,1).content.text)

and

lcText = UPPER(thisform.oDoc.text)

But WORD does not like either of them.

Do you know the syntax to select the text from within a table cell ?


Don


 

Don,

You're right. I didn't notice.

Assuming you only have one table in the document, the following will retrieve the text from cell(2,1):

lcText = oDoc.Tables(1).Cell(2,1).Range.Text

where oDoc is an object ref to the document.

Can you figure it out from there?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
Yep, should be able to. Thanks.


Don


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top