Avatar of Bryce Bassett
Bryce Bassett
Flag for United States of America asked on

WordWrapBehind image wrapping not working in VBA?

This seems pretty straightforward but I am having trouble for some reason.  Could someone please look at my code below and discover why VBA is failing to set the image behind the text?

I initially insert the signature as an Inline shape into a content control so it's in the right position and so I can outdent it.  But then I want to push it behind the typed name so it looks more like a real signature.  That's where my code fails.  

Using Word 365, Windows 10.

'-------------ADD SIGNATURE IMAGE
'get signature image file to use from registry
mysignaturefile = GetSetting("Microsoft Word", "MyClient", "signaturefile", "")

'find signature content control
Set sigcc = newdoc.SelectContentControlsByTitle("SignatureImage").Item(1)

' insert signature image into cc as inline shape
Set objpic = newdoc.InlineShapes.AddPicture(FileName:=mysignaturefile, linktofile:=False, Range:=sigcc.Range)

'resize image, name for future reference, and outdent pre-specified amount
With objpic
    .LockAspectRatio = msoTrue
    .Width = InchesToPoints(2.5)
    .Title = "signature"
End With
sigcc.Range.Select
Selection.ParagraphFormat.LeftIndent = InchesToPoints(GetSetting("Microsoft Word", "TBank", "sigoutdent", 0)) * -1

'remove content control (seems to be necessary before setting WordWrap to behing)
sigcc.Delete False

'convert inline shape to floating shape and set Word wrap to behind text
Set ils = newdoc.InlineShapes("signature")
Set shp = ils.ConvertToShape

' NEXT LINE FAILS.  I DON'T GET AN ERROR MESSAGE, BUT AFTER THE MACRO RUNS I CAN MANUALLY SET WRAPPING TO BEHIND TEXT, SO I THINK IT HAS BEEN SUCCESSFULLY CONVERTED TO A FLOATING SHAPE.
shp.WrapFormat.Type = wdWrapBehind

Open in new window

Windows OSVBAMicrosoft Word

Avatar of undefined
Last Comment
Bryce Bassett

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
John Korchok

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Bryce Bassett

ASKER
My scenario is I have created a Word toolbar used by 8 or 10 users in my client's company.  Each of those users has an image file of their own signature that they use to sign the letters produced by the toolbar.  They don't want to share signature images, to prevent anybody else from signing a letter and making it appear it came from them.

That's why my approach seems complex.  I don't think the QuickParts approach would work.

In one 1 they designate where their signature image lives on their machine, and that filename and location is saved in the registry for later retrieval.

Step 2, they enter a bunch of parameters and my tool spits out a letter, and signs it with their signature image.  Inserting it first as an inline image into a content control was so I could positioning the signature image at the exact location I need, and outdent it per their settings.  Then I just want to push it behind the text, so I was converting  the inline shape to a floating shape.  So far so good.  Then I try to push it behind the text, and that's where the macro stalls.  I don't understand why it fails.  But if I change my method to find a bookmark and bring in the signature as a floating shape to begin with, then I can push is behind the text with no problems.  Maybe that's what I'll do.
John Korchok

Your stated scenario makes my suggestion even easier. Just add each signature as AutoText to each user's Normal.dotm file. Use the same name for each AutoText entry, then you can use the same macro for all.

I'm not clear why you want to put the signature behind the text. It's pretty simple to insert a graphic inline, then use Word's paragraph formatting to outdent it.
arnold

Out of sequence, just a question, is your end output a PDF?
Ever consider using the electronic signature option available in newer. Pdfs?
If you have a PKI in the environment, the user would already have a AD personal certificate that can be used to sign electronically a PDF, that will convert into a read-only.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Bryce Bassett

ASKER
I ended up using a floating shape from the beginning, rather than bring it in as inline then convert it to floating.  I can still outdent it.  

The reason for needing to push it behind text is so that the printed name and title overlap the signature image and it looks more realistic.

If it were for my own use, Building Blocks would definitely be the way to go, but since this is deployed to a dozen folks in different settings, I stayed away from that suggestions.

Thanks for the help.