VBA formating callouts

D

D Riggins

This is a strange one. I've created a subroutine in Word 2007 to apply some
formatting to the selected callout. Only problem is that if any property of
the callout is read (or assigned to a variable) the selection changes to
include the originally selected callout and the previous callout (but only
the text box portions of the callouts). This, of course, causes some of the
methods to fail.

I've come up with a workaround but I was wondering if this behavior been
observed before or is it a bug?
 
J

Jean-Guy Marcil

D Riggins said:
This is a strange one. I've created a subroutine in Word 2007 to apply some
formatting to the selected callout. Only problem is that if any property of
the callout is read (or assigned to a variable) the selection changes to
include the originally selected callout and the previous callout (but only
the text box portions of the callouts). This, of course, causes some of the
methods to fail.

I've come up with a workaround but I was wondering if this behavior been
observed before or is it a bug?

Show us the code that causes you grief.
 
D

D Riggins

*******This code fails

x = Selection.Type '<<< this causes the selected shapes to change as
Described in the original post
If x = 8 Or x = 1 Then
With Selection.shaperange
.Fill.Visible = msoFalse
.TextFrame.MarginLeft = InchesToPoints(0.05)
.TextFrame.MarginRight = 0#
.TextFrame.MarginTop = InchesToPoints(0.05)
 
J

Jean-Guy Marcil

D Riggins said:
*******This code fails

x = Selection.Type '<<< this causes the selected shapes to change as
Described in the original post
If x = 8 Or x = 1 Then
With Selection.shaperange
.Fill.Visible = msoFalse
.TextFrame.MarginLeft = InchesToPoints(0.05)
.TextFrame.MarginRight = 0#
.TextFrame.MarginTop = InchesToPoints(0.05)
.
.
.
.TextFrame.TextRange.Select
Selection.Style = ActiveDocument.Styles("Body Char")

<code fails here>
.
.
.


***** This code works

Dim CallShape As Shape
Dim Shapename As String

x = Selection.Type
Set CallShape = Selection.ShapeRange(1)

I do not really have time to look into this, however, your "work around" is,
for me, a standard practice.
I always create objects and used those in the code.
It makes the code sturdier and easier to read.

Also, the Selection object is notoriously flaky and unreliable.

Finally, you should place the "If" statement before the "Set" one. This way,
if the Selection is not a shape, the code will not try to assign a ShapeRange
to a non-shape selection.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top