Results 1 to 2 of 2
  1. #1
    4 Star Lounger
    Join Date
    Aug 2003
    Stroud, United Kingdom
    Thanked 0 Times in 0 Posts

    Range Width for Textbox (2003)

    Hi, I have put together the following code as the basis for adding text boxes above the cursor as I often want to quickly add chord symbols to music lyrics in specific places, and have always used uintil now tabs, which can get ery messy. I was pleased with the results this code gives me.

    I make the paragraphs double spaced, then click a button linked to the macro and add the Chord symbol.

    Sub InsertChordSymbol()
    Dim r As Range, x As Single, y As Single
    Dim strChord As String

    strChord = InputBox("Chord")
    Set r = Selection.Range

    If r.Paragraphs.LineSpacing < r.Font.Size * 2 Then MsgBox ("May need to make paragraph double line spaced")

    x = r.Information(wdHorizontalPositionRelativeToPage)
    y = r.Information(wdVerticalPositionRelativeToPage) - r.Font.Size

    ActiveDocument.Shapes.AddTextbox(msoTextOrientatio nHorizontal, x, y, 7 * Len(strChord), 10).Select

    With Selection
    .Font.Name = "Opus PlainChords"
    .Font.Size = "8"
    .Font.Bold = True
    .ShapeRange.Fill.Visible = msoFalse
    .ShapeRange.Line.Transparency = 0#
    .ShapeRange.Line.Visible = msoFalse
    .ShapeRange.Line.ForeColor.RGB = RGB(0, 0, 0)
    .ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)
    .ShapeRange.TextFrame.MarginLeft = 0#
    .ShapeRange.TextFrame.MarginRight = 0#
    .ShapeRange.TextFrame.MarginTop = 0#
    .ShapeRange.TextFrame.MarginBottom = 0#
    .ShapeRange.WrapFormat.Type = 3
    .ShapeRange.ZOrder 4
    .TypeText Text:=strChord
    .ShapeRange.TextFrame.AutoSize = True
    .ShapeRange.TextFrame.WordWrap = True
    End With

    Set r = Nothing
    End Sub

    I was wondering how I can get a definate value for the range width in points of the text in the textbox with which to use to make the width of the textbox fit snugly. at the moment I am just using a 7 * multiplier, which is ok, but would have thought there would be a range.width or font.width read value? Can you help.

    I am of course going to refine the code, perhaps making a small form with standard chord symbols to help selection....



  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 31 Times in 31 Posts

    Re: Range Width for Textbox (2003)

    You'd probably need Windows API calls to calculate the text width, so if you have a reasonable approximation, I'd leave it at that.

Posting Permissions

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