Consulting

Results 1 to 9 of 9

Thread: Programmatically Formatting Word Callouts

  1. #1
    VBAX Regular HRoarke's Avatar
    Joined
    Aug 2005
    Location
    Raleigh, NC and Washington, DC
    Posts
    6
    Location

    Programmatically Formatting Word Callouts

    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....

    Any help is greatly appreciated.

    Bryan Williams
    Never doubt that a small group of thoughtful, committed people can change the world. Indeed, it is the only thing that ever has.
    --Margaret Mead


  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi and Welcome to VBAX!

    I'm not understanding your question to well.

    Normally you select a range and then just: [vba]
    WordBasic.InsertNewComment[/vba]

    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,
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  3. #3
    VBAX Regular HRoarke's Avatar
    Joined
    Aug 2005
    Location
    Raleigh, NC and Washington, DC
    Posts
    6
    Location
    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:
    [VBA]
    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
    [/VBA]

    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.
    Never doubt that a small group of thoughtful, committed people can change the world. Indeed, it is the only thing that ever has.
    --Margaret Mead


  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi,

    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.
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  5. #5
    VBAX Regular HRoarke's Avatar
    Joined
    Aug 2005
    Location
    Raleigh, NC and Washington, DC
    Posts
    6
    Location

    Clarification

    OK, Joost, here ya go:

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

    [VBA]
    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
    [/VBA]

    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
    Never doubt that a small group of thoughtful, committed people can change the world. Indeed, it is the only thing that ever has.
    --Margaret Mead


  6. #6
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Hi Bryan,

    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.
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  7. #7
    VBAX Regular HRoarke's Avatar
    Joined
    Aug 2005
    Location
    Raleigh, NC and Washington, DC
    Posts
    6
    Location
    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!

    In any case, I appreciate your efforts.....
    Never doubt that a small group of thoughtful, committed people can change the world. Indeed, it is the only thing that ever has.
    --Margaret Mead


  8. #8
    Administrator
    VP-Knowledge Base
    VBAX Guru MOS MASTER's Avatar
    Joined
    Apr 2005
    Location
    Breda, The Netherlands
    Posts
    3,281
    Location
    Quote Originally Posted by HRoarke
    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!

    In any case, I appreciate your efforts.....
    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.
    _________
    Groetjes,

    Joost Verdaasdonk
    M.O.S. Master

    Mark your thread solved, when it has been, by hitting the Thread Tools dropdown at the top of the thread.
    (I don't answer questions asked through E-mail or PM's)

  9. #9
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •