PDA

View Full Version : Programmatically Formatting Word Callouts



HRoarke
08-02-2005, 12:20 PM
Hello all -

Background:
I am creating an add-in for Word (Min version = Office 2000/ Word X). One requirement is to add callouts under certatin conditions. When a given condition is met, a range is selected and a bookmark and a callout added that reference that range.
The question:
How does one insure that the origin of the callout line (the place that the callout points to) points to, say, the beginning or end of the range (or heck, any ol' where in the range, like maybe the "middle"). I can get all other formatting that I need, but the setting the origin of the callout line eludes me....:banghead:

Any help is greatly appreciated.

Bryan Williams

MOS MASTER
08-03-2005, 10:25 AM
Hi and Welcome to VBAX! :hi:

I'm not understanding your question to well.

Normally you select a range and then just:
WordBasic.InsertNewComment

To add a new comment balloon and just typetext in it...
This will set the range of the balloon arround the selection.

So could you add a sample of what you have so fare and point out where it's failing?

HTH, :whistle:

HRoarke
08-03-2005, 10:40 AM
Hello Joost -

I'm doing this in VBA and the code must run on both a PC and MAC, so WordBasic (an automation object) doesn't work, since MAC don't support automation sourcing.

That said, the code snippet:

the shape has been added as a msoShapeLineCallout1...

Doc.Shapes(MarkName).Select

With Selection
'bring the shape to the front of the text
.ShapeRange.ZOrder msoBringInFrontOfText
.ShapeRange.Fill.Visible = msoTrue
'auto-attach the anchor line
.ShapeRange.Callout.AutoAttach = True
'lock the anchor to the target range
.ShapeRange.LockAnchor = True
.ShapeRange.Callout.AutomaticLength
'add a fill color
.ShapeRange.Fill.Solid
.ShapeRange.Fill.ForeColor.RGB = RGB(255, 255, 153)
.ShapeRange.Fill.Transparency = 0.5
'format the arrows
.ShapeRange.Line.BeginArrowheadLength = msoArrowheadLengthMedium
.ShapeRange.Line.BeginArrowheadWidth = msoArrowheadNarrow
.ShapeRange.Line.BeginArrowheadStyle = msoArrowheadStealth
.ShapeRange.Line.EndArrowheadLength = msoArrowheadLengthMedium
.ShapeRange.Line.EndArrowheadWidth = msoArrowheadWidthMedium
.ShapeRange.Line.EndArrowheadStyle = msoArrowheadNone
'format the callout position
.ShapeRange.RelativeHorizontalPosition = wdRelativeHorizontalPositionColumn
.ShapeRange.Top = InchesToPoints(-0.1)
.ShapeRange.RelativeVerticalPosition = wdRelativeVerticalPositionLine
.ShapeRange.Left = InchesToPoints(8.25)
End With


Nothing is **failing** per se, it's just that the callout's line origin doesn't point to the range, nor is it locked to the range (for example, if the callout is subseqently moved by the user). It seems this should be an exceptionally simple thing to do, but I see NO WAY to do it. Frustrating....

Thanks in advance for any assistance you may be able to provide.

MOS MASTER
08-03-2005, 11:02 AM
Hi, :yes

Ok we have a misunderstanding over here.

I thought you where talking about Comment boxes when you where talking about Callout.

But now I see you're talking about a Shape from the callout menu.

From the code I can't get any clue on how that shape should be attached to a range and I really think I'm not getting the question yet.

So instead of code could you add a document with this code with the macro and tell me what that macro should do to the shape in that document and how it should be attached to the range. (And what range is that?..perhaps mark it red or something)

I must understand it first to be of help. :whistle:

HRoarke
08-03-2005, 12:13 PM
OK, Joost, here ya go:

The code is from a subroutine that is called when a range needs to be "marked".


Private Sub MarkRange(ByRef TargetRange As Range, ByVal MarkName As String, Description As String)

'..addition of the bookmark not included

'add a callout anchored to the target range
Doc.Shapes.AddShape(msoShapeLineCallout1, 0, 0, 75, 50, TargetRange).Select
Selection.ShapeRange.Name = MarkName
'add and format the descriptive text
Selection.ShapeRange.TextFrame.TextRange.Select
With Selection
.Text = Description
.Font.Size = 8
.Font.Color = wdColorBlue
.Collapse
End With

Doc.Shapes(MarkName).Select

With Selection
'bring the shape to the front of the text
.ShapeRange.ZOrder msoBringInFrontOfText
.ShapeRange.Fill.Visible = msoTrue
'auto-attach the anchor line
.ShapeRange.Callout.AutoAttach = True
'lock the anchor to the target range
.ShapeRange.LockAnchor = True
.ShapeRange.Callout.AutomaticLength
'add a fill color
.ShapeRange.Fill.Solid
.ShapeRange.Fill.ForeColor.RGB = RGB(255, 255, 153)
.ShapeRange.Fill.Transparency = 0.5
'format the arrows
.ShapeRange.Line.BeginArrowheadLength = msoArrowheadLengthMedium
.ShapeRange.Line.BeginArrowheadWidth = msoArrowheadNarrow
.ShapeRange.Line.BeginArrowheadStyle = msoArrowheadStealth
.ShapeRange.Line.EndArrowheadLength = msoArrowheadLengthMedium
.ShapeRange.Line.EndArrowheadWidth = msoArrowheadWidthMedium
.ShapeRange.Line.EndArrowheadStyle = msoArrowheadNone
'format the callout position
.ShapeRange.RelativeHorizontalPosition = wdRelativeHorizontalPositionColumn
.ShapeRange.Top = InchesToPoints(-0.1)
.ShapeRange.RelativeVerticalPosition = wdRelativeVerticalPositionLine ' wdRelativeVerticalPositionParagraph
.ShapeRange.Left = InchesToPoints(8.25)
End With

'... error handling, clean-up code not included

end sub


So, if you add this code as a macro in a doc and pass the macro a range, name and description, you'll see what I'm doing, and as mentioned, the goal is to have the callout line's origin be somewhere in the range, e.g. beginning, end, middle, etc.

Thanks again,

Bryan

MOS MASTER
08-03-2005, 12:41 PM
Hi Bryan, :yes

Well this is a lot harder then I thought and I'm not able to find a sollution just yet.

I will try out some more stuff later but I'm having doubts if this can be achieved. :whistle:

HRoarke
08-03-2005, 12:46 PM
I hate to hear that, Joost. I haven't done much VBA since the mid-90s and it's certainly a lot better than it was then, but GOSH, this seems like the simplest thing! :dunno

In any case, I appreciate your efforts.....:clap:

MOS MASTER
08-03-2005, 01:03 PM
I hate to hear that, Joost. I haven't done much VBA since the mid-90s and it's certainly a lot better than it was then, but GOSH, this seems like the simplest thing! :dunno

In any case, I appreciate your efforts.....:clap:

You're welcome.

But possitioning shapes is very tricky cause they are in the drawing layer of Word and like to flowt in unacspected directions. :rofl:

fumei
08-07-2005, 04:36 AM
Uh, gentlermen. The callout end point is always the the Selection.Range.End integer. That is where the line starts. If you notice, if the the Selection is greater than 1 (that is, more than one character is selected), the callout line still starts at the Selection.Range.End, but it adds a indicator where the selection.range.start was.

Therefore the solution is quite easy. Make a separate Selection.Setrange value to use as the callout origin.