troubleshooting Question

WordWrapBehind image wrapping not working in VBA?

Avatar of Bryce Bassett
Bryce BassettFlag for United States of America asked on
Windows OSVBAMicrosoft Word
5 Comments1 Solution13 ViewsLast Modified:
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
ASKER CERTIFIED SOLUTION
John Korchok
Production Manager
Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros