PDA

View Full Version : can i change a picture in doc based on a formfield result with vba?



RoadDog83
09-25-2009, 10:00 AM
i have a doc that has a signature jpeg at the bottom. i have a user form that the person fills out and types in who the letter is from.

im wondering if based on what name they choose from a combo box the picture of there signature will automically change.

is this possible?

gmaxey
09-25-2009, 03:18 PM
Yes it is possible. One way to do this is to have the default and other various signatures saved as named AutoText entries.

The defualt signature in the template would be represented by an AutoText field. Something like:

{ AutoText DefaultSig }

Your UserForm code can then replace the defualt signature with the one corresponding to the selection in the ComboBox. Say Mary Smith was choosen. You would then change the AutoText field to display the AutoText entry for Mary Smith's signature saved as SigMarySmith:

For Each oFld In oRng.Fields
If oFld.Type = wdFieldAutoText Then
If InStr(oFld.Code.Text, "DefaultSig") > 0 Then
oFld.Code.Text = Replace(oFld.Code, "DefaultSig", "SigMarySmith")
oFld.Update
Exit For
End If
End If

RoadDog83
09-25-2009, 06:00 PM
man that is confusing. im trying to do it on my document but its just not workin out for me. any chance you could post a sample document?

gmaxey
09-25-2009, 06:57 PM
A sample is attached.

RoadDog83
09-25-2009, 09:58 PM
doesnt seem to work. could it be that i dont have those particular sigs saved as an autotext?

RoadDog83
09-25-2009, 10:03 PM
no i dont think that will work i replaced some of the list box with my own sigs that i saved as autotext and they didnt work.

gmaxey
09-26-2009, 05:49 AM
RoadDog83,

Works here. What version of Word do you have? If you send me an e-mail I wll send you the working template (I can't attach a template to this message).

RoadDog83
09-26-2009, 11:52 AM
okay