Consulting

Results 1 to 4 of 4

Thread: Measure height of textbox

  1. #1
    VBAX Newbie
    Joined
    Oct 2014
    Posts
    3
    Location

    Measure height of textbox

    Hello,

    I need to measure the height of a textbox in order to place other objects. The height of the textbox depends on the length of the text which is dynamically updated, and i have sat autosize=true.
    It is placed on a worksheet. This is the code, which i have used to generate it:

    ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, chartAreaLeft, plotAreaTop + chartAreaHeight + AfstandChart + 2 * AfstandKategorier, ForklaringBredde, 1.35 * ForklaringHøjde).Name = "spgOverskriftT" & "," & p
    ActiveSheet.Shapes.Range(Array("spgOverskriftT" & "," & p)).Select
        Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = "Tilpas"
    Selection.ShapeRange.TextFrame2.TextRange.Font.Size = 11
    Selection.ShapeRange.TextFrame2.TextRange.Font.Name = "Lucida Bright"
    Selection.ShapeRange.Line.Visible = msoFalse
    Selection.ShapeRange.TextFrame2.VerticalAnchor = msoAnchorMiddle
    Selection.ShapeRange.Fill.Visible = msoFalse
    Selection.ShapeRange.ZOrder msoBringToFront
    I really hope that someone can help me
    Last edited by SamT; 10-22-2014 at 11:12 AM.

  2. #2
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    This is your code, I just edited it to make it faster and easier to understand. I am not saying that it even works.
    With ActiveSheet.Shapes
    .AddTextbox(msoTextOrientationHorizontal,  _
    chartAreaLeft, _
    plotAreaTop + chartAreaHeight + AfstandChart + 2 *  AfstandKategorier, _
    ForklaringBredde, 1.35 * ForklaringHøjde).Name =  "spgOverskriftT" & "," & p
    
    With .Range(Array("spgOverskriftT" & "," & p))
        With .ShapeRange(1).TextFrame2.TextRange
    .Characters.Text = "Tilpas"
    .Font.Size = 11
    .Font.Name = "Lucida Bright"
    End With 'ShapeRange(1).TextFrame2.TextRange
    
    With .ShapeRange
    .Line.Visible = msoFalse
    .TextFrame2.VerticalAnchor = msoAnchorMiddle
    .Fill.Visible = msoFalse
    .ZOrder msoBringToFront
    End With 'ShapeRange
    
    End With 'Range(Array("spgOverskriftT" & "," & p))
    End With 'ActiveSheet.Shapes
    If it works, this is how I would change it to get the values you're looking for. And I am not saying this will work, either

    Dim Lft As Double
    Dim Wdth As Double
    Dim Tp As Double
    Dim Hght As Double
    
    With ActiveSheet.Shapes
      .AddTextbox(msoTextOrientationHorizontal, _
      chartAreaLeft, _
      plotAreaTop + chartAreaHeight + AfstandChart + 2 * AfstandKategorier, _
      ForklaringBredde, 1.35 * ForklaringHøjde).Name = "spgOverskriftT" & "," & p
      
      With .Range(Array("spgOverskriftT" & "," & p))
        With .ShapeRange(1)
          With .TextFrame2
             Lft = .Left
             Wdth = .Width
             Tp = .Top
             Hgth = .Height
        
            With .TextRange
            .Characters.Text = "Tilpas"
            .Font.Size = 11
            .Font.Name = "Lucida Bright"
            End With 'TextRange
          End With 'TextFrame2.
      
          'The rest is with ShapeRange
          .Line.Visible = msoFalse
          .TextFrame2.VerticalAnchor = msoAnchorMiddle
          .Fill.Visible = msoFalse
          .ZOrder msoBringToFront
      
        End With 'ShapeRange
      End With 'Range(Array("spgOverskriftT" & "," & p))
    End With 'ActiveSheet.Shapes
    Now you have the TextFrame's Lft, Wdth, Tp, and Hght to use as you want.
    Last edited by SamT; 10-22-2014 at 11:46 AM.
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Newbie
    Joined
    Oct 2014
    Posts
    3
    Location
    Quote Originally Posted by SamT View Post
    This is your code, I just edited it to make it faster and easier to understand. I am not saying that it even works.
    With ActiveSheet.Shapes
    .AddTextbox(msoTextOrientationHorizontal,  _
    chartAreaLeft, _
    plotAreaTop + chartAreaHeight + AfstandChart + 2 *  AfstandKategorier, _
    ForklaringBredde, 1.35 * ForklaringHøjde).Name =  "spgOverskriftT" & "," & p
    
    With .Range(Array("spgOverskriftT" & "," & p))
        With .ShapeRange(1).TextFrame2.TextRange
    .Characters.Text = "Tilpas"
    .Font.Size = 11
    .Font.Name = "Lucida Bright"
    End With 'ShapeRange(1).TextFrame2.TextRange
    
    With .ShapeRange
    .Line.Visible = msoFalse
    .TextFrame2.VerticalAnchor = msoAnchorMiddle
    .Fill.Visible = msoFalse
    .ZOrder msoBringToFront
    End With 'ShapeRange
    
    End With 'Range(Array("spgOverskriftT" & "," & p))
    End With 'ActiveSheet.Shapes
    If it works, this is how I would change it to get the values you're looking for. And I am not saying this will work, either

    Dim Lft As Double
    Dim Wdth As Double
    Dim Tp As Double
    Dim Hght As Double
    
    With ActiveSheet.Shapes
      .AddTextbox(msoTextOrientationHorizontal, _
      chartAreaLeft, _
      plotAreaTop + chartAreaHeight + AfstandChart + 2 * AfstandKategorier, _
      ForklaringBredde, 1.35 * ForklaringHøjde).Name = "spgOverskriftT" & "," & p
      
      With .Range(Array("spgOverskriftT" & "," & p))
        With .ShapeRange(1)
          With .TextFrame2
             Lft = .Left
             Wdth = .Width
             Tp = .Top
             Hgth = .Height
        
            With .TextRange
            .Characters.Text = "Tilpas"
            .Font.Size = 11
            .Font.Name = "Lucida Bright"
            End With 'TextRange
          End With 'TextFrame2.
      
          'The rest is with ShapeRange
          .Line.Visible = msoFalse
          .TextFrame2.VerticalAnchor = msoAnchorMiddle
          .Fill.Visible = msoFalse
          .ZOrder msoBringToFront
      
        End With 'ShapeRange
      End With 'Range(Array("spgOverskriftT" & "," & p))
    End With 'ActiveSheet.Shapes
    Now you have the TextFrame's Lft, Wdth, Tp, and Hght to use as you want.
    Thank you very much! That worked!

  4. #4
    Moderator VBAX Wizard Aussiebear's Avatar
    Joined
    Dec 2005
    Location
    Queensland
    Posts
    5,136
    Location
    [Quote} And I'm not saying this will work, either[/Quote]



    Not bad Sam.
    Remember To Do the Following....
    Use [Code].... [/Code] tags when posting code to the thread.
    Mark your thread as Solved if satisfied by using the Thread Tools options.
    If posting the same issue to another forum please show the link

Posting Permissions

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