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

Inserting scanned signature into ms word document (macro) 1

Status
Not open for further replies.

doneirik

Technical User
Nov 23, 2007
30
NL
Hi,

I need to insert a number of signatures into ms-word document automatically,...I think this can be achieved by means of a macro, but I´m uncertain as to how to go about it...

I will most likely store 30-40 scanned signatures on a server. I have the possibility to run macros from a third party software I use for document management, so the missing link is that I need a macro for getting the signature from the server (signature retrieved must be dependent on the user logged in) and inserting this signature into the doc.

any suggestions?

best regards
d.

 
Hi d.

What you need for this, is
a) some code to read the current user name
b) the signatures named accordingly and stored in a specific folder
c) some word macro code to embed the graphic

So if you store all signatures on a server (Here drive "X"), say in a asubfolder "Sigs", all in GIF format (for example), and all named exactly like the user name
(e.g. "X:\Sigs\doneirik.gif"), then this sample should do the trick:

Code:
[b]Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long[/b]

Private Sub Sign_Docs()
Dim user_name As String
Dim ret_len As Long
dim src as String

' Get the user's name.
[b]user_name = Space$(32)
GetUserName user_name, 32
user_name = RTrim(user_name) 'remove superfluous spaces
user_name = Left(user_name, Len(user_name) - 1) 'cut off end marker[/b]

...
[b]src="X:\Sigs\" & user_name & ".gif"[/b]
wd.Selection.InlineShapes.AddPicture src, True, False

Just pack the image-embedding code piece (last line) in a loop which opens and saves/closes all docs subseqently, et voilá.

Note: Don't forget to make backups first!!
:)


[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Note: Don't forget to make backups first!!
:)"

Yup yup yup

donerik, you could also possibly use Environs("username") to pick up the login name. MakeItSo has, essentially, given you the way to go.

His code inserts the image as an InlineShape. I agree that is probably the way you would like it. However, it may not. You may need it as a moveable Shape instead.

Do some testing first on the user name.
Code:
user_name = RTrim(user_name) 'remove superfluous spaces
This does not remove superfluous spaces. It removes the trailing spaces. It will not remove any space inside the string. This may not work fully/correctly, depending on how your login names are set up. Are spaces permitted? Do your login names have dots in them? Mine is gerry.knight, so that dot has to be dealt with. This is just basic string manipulation so whatever your system does for username can certainly be handled.

MakeItSo's point regarding the image file naming is very important.

"b) the signatures named accordingly and stored in a specific folder"

"all named exactly like the user name"

You could have an array of image file names, and then match to that from the retrieved username. It would be easier though, as MakeItSo notes, if the image filenames matched to username.

However, this is technically a VBA question. So if you need to follow this up with detailed questions/help, please post a thread in that forum.

faq219-2884

Gerry
My paintings and sculpture
 
Thanks for the additional input, Gerry.
Very useful - as always.
[thumbsup]

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top