Inserting an image from vba

M

M.L.Srinivas

I want to insert electronic signature (saved in the form
of a scanned image)into a word document from vba. I will
specify the place of insertion by creating a bookmark at
that place.

How to do this? Please suggest

Srinivas
 
H

Helmut Weber

Hi M.L.,
like this, without commenting or using all parameters:
Sub Makro2()
With ActiveDocument
.InlineShapes.AddPicture _
FileName:="C:\test\test.bmp", _
Range:=.Bookmarks("hier").Range
End With
' or relative to the paragraph the bookmark is in
With ActiveDocument
.Shapes.AddPicture _
FileName:="C:\test\test.bmp", _
Left:=0, _
Top:=0, _
Anchor:=.Bookmarks("hier").Range
End With
End Sub
 
M

M.L.Srinivas

Hi Weber,

Thanks for your time. It worked fine. I need your help in
another task related to this.

My client is asking for a field in place of bookmark. Coz,
the signature might be at multiple places in a single
document.

So, I want to create an empty field and then change the
type to includepicture and insert the signature.

This is what I tried:
f is field and w is my word object

Set f = w.ActiveDocument.Fields.Add
(Range:=w.Selection.Range, _
Type:=wdFieldEmpty, Text:="Signature")

to insert the picture i used:

Set f = w.ActiveDocument.Fields("Signature")

f.Type = wdFieldIncludePicture
f.code.Text = "D:\sign.gif"
f.Update

I faced to problems:
1) While creating empty field thru vba
--Error! Bookmark not defined.-- in place of the field.

2) to test the sec. one and created a field manually by
using ctrl+f9 and typed the code {signature \* MERGEFORMAT}
and executed to insert the pic.

It says the field type is read only and can not be set.


How to do this using a field?

Any sort of help is appreciated.

Thanks
Srinivas
 
H

Helmut Weber

Hi M.L.,
what do M. and L. stand for? :)
As far as I understand your question, you would like to
insert a signature at a certain place in a doc, and have
appear it on other places, after updating fields.
I have to admit, I hate coding with fields. IMHO there is
too often no logical way leading to a solution.
And I am therefore no good at it.
What I would try goes like this:
Manually, e.g. in a template:
Set a bookmark "signature"
set references to that bookmark, wherever you like.
{ REF signature }
Programmatically:
Add a field at the bookmark "signature",
which causes the bookmark to disappear.
Set the bookmark again to the range of the field.
Update all fields.
---
Dim f As Field
With ActiveDocument
Set f = .Fields.Add( _
Range:=.Bookmarks("signature").Range, _
Type:=wdFieldEmpty, _
Text:="INCLUDEPICTURE ""c:\\test\\test.bmp"" ", _
PreserveFormatting:=True)
f.Select
Selection.Bookmarks.Add "Signature"
.Fields.Update
End With
 
M

M.L.Srinivas

Hi Weber,

M.L. doesn't stand for millilitre that's for sure :)

Thanks for your solution. Why I opted for fields coz, I
thought bookmark cannot be repeated in a document as I'm
not aware of referencing a bookmark.

Thanks a lot for your time. My task is accomplished.


M.L.Srinivas (Not Millilitre Srinivas):)
 
Top